Exit early when encountering parsing errors (#10213)

# Description
This PR tries to fix #10184 and #10182.
This commit is contained in:
nibon7 2023-09-05 20:36:37 +08:00 committed by GitHub
parent 9a4dad6ca1
commit e566a073dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -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();

View File

@ -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"));
}

9
tests/fixtures/eval/script.nu vendored Normal file
View File

@ -0,0 +1,9 @@
def main [] {
somefunc "foo"
}
def somefunc [
somearg: unknown_type
] {
echo $somearg
}