mirror of
https://github.com/denoland/deno.git
synced 2025-02-20 20:33:42 -05:00
fix(cli): improve deno compile
error messages (#13944)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
b01a817f36
commit
3f7d2fc1e9
2 changed files with 48 additions and 9 deletions
|
@ -306,8 +306,14 @@ fn compile_with_file_exists_error() {
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!output.status.success());
|
assert!(!output.status.success());
|
||||||
let expected_stderr =
|
let expected_stderr = format!(
|
||||||
format!("Could not compile: {:?} is a file.\n", &file_path);
|
concat!(
|
||||||
|
"Could not compile to file '{}' because its parent directory ",
|
||||||
|
"is an existing file. You can use the `--output <file-path>` flag to ",
|
||||||
|
"provide an alternative name.\n",
|
||||||
|
),
|
||||||
|
file_path.display(),
|
||||||
|
);
|
||||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
assert!(stderr.contains(&expected_stderr));
|
assert!(stderr.contains(&expected_stderr));
|
||||||
}
|
}
|
||||||
|
@ -334,8 +340,14 @@ fn compile_with_directory_exists_error() {
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!output.status.success());
|
assert!(!output.status.success());
|
||||||
let expected_stderr =
|
let expected_stderr = format!(
|
||||||
format!("Could not compile: {:?} is a directory.\n", &exe);
|
concat!(
|
||||||
|
"Could not compile to file '{}' because a directory exists with ",
|
||||||
|
"the same name. You can use the `--output <file-path>` flag to ",
|
||||||
|
"provide an alternative name."
|
||||||
|
),
|
||||||
|
exe.display()
|
||||||
|
);
|
||||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
assert!(stderr.contains(&expected_stderr));
|
assert!(stderr.contains(&expected_stderr));
|
||||||
}
|
}
|
||||||
|
@ -363,8 +375,14 @@ fn compile_with_conflict_file_exists_error() {
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!output.status.success());
|
assert!(!output.status.success());
|
||||||
let expected_stderr =
|
let expected_stderr = format!(
|
||||||
format!("Could not compile: cannot overwrite {:?}.\n", &exe);
|
concat!(
|
||||||
|
"Could not compile to file '{}' because the file already exists ",
|
||||||
|
"and cannot be overwritten. Please delete the existing file or ",
|
||||||
|
"use the `--output <file-path` flag to provide an alternative name."
|
||||||
|
),
|
||||||
|
exe.display()
|
||||||
|
);
|
||||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
dbg!(&stderr);
|
dbg!(&stderr);
|
||||||
assert!(stderr.contains(&expected_stderr));
|
assert!(stderr.contains(&expected_stderr));
|
||||||
|
|
|
@ -183,7 +183,14 @@ pub async fn write_standalone_binary(
|
||||||
if output.exists() {
|
if output.exists() {
|
||||||
// If the output is a directory, throw error
|
// If the output is a directory, throw error
|
||||||
if output.is_dir() {
|
if output.is_dir() {
|
||||||
bail!("Could not compile: {:?} is a directory.", &output);
|
bail!(
|
||||||
|
concat!(
|
||||||
|
"Could not compile to file '{}' because a directory exists with ",
|
||||||
|
"the same name. You can use the `--output <file-path>` flag to ",
|
||||||
|
"provide an alternative name."
|
||||||
|
),
|
||||||
|
output.display()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we don't overwrite any file not created by Deno compiler.
|
// Make sure we don't overwrite any file not created by Deno compiler.
|
||||||
|
@ -199,7 +206,14 @@ pub async fn write_standalone_binary(
|
||||||
has_trailer = magic_trailer == MAGIC_TRAILER;
|
has_trailer = magic_trailer == MAGIC_TRAILER;
|
||||||
}
|
}
|
||||||
if !has_trailer {
|
if !has_trailer {
|
||||||
bail!("Could not compile: cannot overwrite {:?}.", &output);
|
bail!(
|
||||||
|
concat!(
|
||||||
|
"Could not compile to file '{}' because the file already exists ",
|
||||||
|
"and cannot be overwritten. Please delete the existing file or ",
|
||||||
|
"use the `--output <file-path` flag to provide an alternative name."
|
||||||
|
),
|
||||||
|
output.display()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove file if it was indeed a deno compiled binary, to avoid corruption
|
// Remove file if it was indeed a deno compiled binary, to avoid corruption
|
||||||
|
@ -208,7 +222,14 @@ pub async fn write_standalone_binary(
|
||||||
} else {
|
} else {
|
||||||
let output_base = &output.parent().unwrap();
|
let output_base = &output.parent().unwrap();
|
||||||
if output_base.exists() && output_base.is_file() {
|
if output_base.exists() && output_base.is_file() {
|
||||||
bail!("Could not compile: {:?} is a file.", &output_base);
|
bail!(
|
||||||
|
concat!(
|
||||||
|
"Could not compile to file '{}' because its parent directory ",
|
||||||
|
"is an existing file. You can use the `--output <file-path>` flag to ",
|
||||||
|
"provide an alternative name.",
|
||||||
|
),
|
||||||
|
output_base.display(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
tokio::fs::create_dir_all(output_base).await?;
|
tokio::fs::create_dir_all(output_base).await?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue