forked from extern/nushell
Exit early when encountering parsing errors (#10213)
# Description This PR tries to fix #10184 and #10182.
This commit is contained in:
parent
9a4dad6ca1
commit
e566a073dc
@ -107,6 +107,11 @@ pub fn evaluate_file(
|
|||||||
trace!("parsing file: {}", file_path_str);
|
trace!("parsing file: {}", file_path_str);
|
||||||
let block = parse(&mut working_set, Some(file_path_str), &file, false);
|
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 {
|
for block in &mut working_set.delta.blocks {
|
||||||
if block.signature.name == "main" {
|
if block.signature.name == "main" {
|
||||||
block.signature.name = source_filename.to_string_lossy().to_string();
|
block.signature.name = source_filename.to_string_lossy().to_string();
|
||||||
|
@ -6,3 +6,13 @@ fn source_file_relative_to_file() {
|
|||||||
|
|
||||||
assert!(actual.err.contains("redefined"));
|
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
9
tests/fixtures/eval/script.nu
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
def main [] {
|
||||||
|
somefunc "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
def somefunc [
|
||||||
|
somearg: unknown_type
|
||||||
|
] {
|
||||||
|
echo $somearg
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user