diff --git a/crates/nu-cli/src/eval_file.rs b/crates/nu-cli/src/eval_file.rs index 748b92d4b..0fc84cf88 100644 --- a/crates/nu-cli/src/eval_file.rs +++ b/crates/nu-cli/src/eval_file.rs @@ -107,6 +107,11 @@ pub fn evaluate_file( trace!("parsing file: {}", file_path_str); let block = parse(&mut working_set, Some(file_path_str), &file, false); + if let Some(err) = working_set.parse_errors.first() { + report_error(&working_set, err); + std::process::exit(1); + } + for block in &mut working_set.delta.blocks { if block.signature.name == "main" { block.signature.name = source_filename.to_string_lossy().to_string(); diff --git a/tests/eval/mod.rs b/tests/eval/mod.rs index 9d7492389..f3af92376 100644 --- a/tests/eval/mod.rs +++ b/tests/eval/mod.rs @@ -6,3 +6,13 @@ fn source_file_relative_to_file() { assert!(actual.err.contains("redefined")); } + +#[test] +fn run_file_parse_error() { + let actual = nu!( + cwd: "tests/fixtures/eval", + "nu script.nu" + ); + + assert!(actual.err.contains("unknown type")); +} diff --git a/tests/fixtures/eval/script.nu b/tests/fixtures/eval/script.nu new file mode 100644 index 000000000..b67e2e363 --- /dev/null +++ b/tests/fixtures/eval/script.nu @@ -0,0 +1,9 @@ +def main [] { + somefunc "foo" +} + +def somefunc [ + somearg: unknown_type +] { + echo $somearg +}