From e6fbf7d01d1d0e2076549cb590d517372fd32ffa Mon Sep 17 00:00:00 2001 From: Wind Date: Tue, 16 Apr 2024 21:47:10 +0800 Subject: [PATCH] Unify `working_set.error` usage. (#12531) # Description A little refactor that use `working_set.error` rather than `working_set.parse_errors.push`, which is reported here: https://github.com/nushell/nushell/pull/12238 > Inconsistent error reporting. Usage of both working_set.error() and working_set.parse_errors.push(). Using ParseError::Expected for an invalid variable name when there's ParseError::VariableNotValid (from parser.rs:5237). Checking variable names manually when there's is_variable() (from parser.rs:2905). # User-Facing Changes NaN # Tests + Formatting Done --- crates/nu-parser/src/parse_keywords.rs | 6 +++--- crates/nu-parser/src/parser.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index b46a9f06f7..5c770015d9 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -459,7 +459,7 @@ pub fn parse_def( let block = working_set.get_block_mut(*block_id); block.signature = Box::new(sig.clone()); } - _ => working_set.parse_errors.push(ParseError::Expected( + _ => working_set.error(ParseError::Expected( "definition body closure { ... }", arg.span, )), @@ -2957,7 +2957,7 @@ pub fn parse_let(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline ); if let Some(parse_error) = parse_error { - working_set.parse_errors.push(parse_error) + working_set.error(parse_error) } let rvalue_span = nu_protocol::span(&spans[(span.0 + 1)..]); @@ -3221,7 +3221,7 @@ pub fn parse_mut(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline ); if let Some(parse_error) = parse_error { - working_set.parse_errors.push(parse_error) + working_set.error(parse_error); } let rvalue_span = nu_protocol::span(&spans[(span.0 + 1)..]); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 6cf3a84b9b..310d8e44ca 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -2915,7 +2915,7 @@ pub fn parse_var_with_opt_type( lex_signature(&type_bytes, full_span.start, &[b','], &[], true); if let Some(parse_error) = parse_error { - working_set.parse_errors.push(parse_error); + working_set.error(parse_error); } let ty = parse_type(working_set, &type_bytes, tokens[0].span); @@ -3045,7 +3045,7 @@ pub fn parse_input_output_types( lex_signature(bytes, full_span.start, &[b'\n', b'\r', b','], &[], true); if let Some(parse_error) = parse_error { - working_set.parse_errors.push(parse_error); + working_set.error(parse_error); } let mut output = vec![];