diff --git a/crates/nu-command/src/formats/from/nuon.rs b/crates/nu-command/src/formats/from/nuon.rs index 8e20f926686f2..68b2c016a9f29 100644 --- a/crates/nu-command/src/formats/from/nuon.rs +++ b/crates/nu-command/src/formats/from/nuon.rs @@ -56,7 +56,7 @@ impl Command for FromNuon { fn run( &self, - _engine_state: &EngineState, + engine_state: &EngineState, _stack: &mut Stack, call: &Call, input: PipelineData, @@ -64,19 +64,12 @@ impl Command for FromNuon { let head = call.head; let (string_input, metadata) = input.collect_string_strict(head)?; - let engine_state = EngineState::new(); + let engine_state = engine_state.clone(); let mut working_set = StateWorkingSet::new(&engine_state); - - let _ = working_set.add_file("nuon file".to_string(), string_input.as_bytes()); - let mut error = None; - - // Most of the 'work' in converting from Nuon is simply pushing it through the Nu parser. - let (lexed, err) = nu_parser::lex(string_input.as_bytes(), 0, &[b'\n', b'\r'], &[], true); - error = error.or(err); - - let (mut block, err) = nu_parser::parse_block(&mut working_set, &lexed, true, &[], false); + let (mut block, err) = + nu_parser::parse(&mut working_set, None, string_input.as_bytes(), false, &[]); error = error.or(err); if let Some(pipeline) = block.pipelines.get(1) { diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index 29a381ab3b0cf..8226a3f0f2280 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -340,6 +340,14 @@ fn quotes_some_strings_necessarily() { assert_eq!(actual.out, "list"); } +#[test] +fn read_code_should_fail_rather_than_panic() { + let actual = nu!(cwd: "tests/fixtures/formats", pipeline( + r#"open code.nu | from nuon"# + )); + assert!(actual.err.contains("error when parsing")) +} + proptest! { #[test] fn to_nuon_from_nuon(c: char) { diff --git a/tests/fixtures/formats/code.nu b/tests/fixtures/formats/code.nu new file mode 100644 index 0000000000000..26263cf31e31f --- /dev/null +++ b/tests/fixtures/formats/code.nu @@ -0,0 +1 @@ +register \ No newline at end of file