diff --git a/src/errors.rs b/src/errors.rs index 84bb96f037..0f6d1b0b42 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -140,7 +140,15 @@ impl ShellError { use language_reporting::*; match error { - nom::Err::Incomplete(_) => unreachable!(), + nom::Err::Incomplete(_) => { + // TODO: Get span of EOF + let diagnostic = Diagnostic::new( + Severity::Error, + format!("Parse Error: Unexpected end of line"), + ); + + ShellError::diagnostic(diagnostic) + } nom::Err::Failure(span) | nom::Err::Error(span) => { let diagnostic = Diagnostic::new(Severity::Error, format!("Parse Error")) .with_label(Label::new_primary(Span::from(span.0))); diff --git a/src/parser/hir/baseline_parse_tokens.rs b/src/parser/hir/baseline_parse_tokens.rs index 248169bbb8..f0716d3438 100644 --- a/src/parser/hir/baseline_parse_tokens.rs +++ b/src/parser/hir/baseline_parse_tokens.rs @@ -231,12 +231,16 @@ pub fn baseline_parse_semantic_token( TokenNode::Call(_call) => unimplemented!(), TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, context, source), TokenNode::Pipeline(_pipeline) => unimplemented!(), - TokenNode::Operator(_op) => unreachable!(), - TokenNode::Flag(_flag) => Err(ShellError::unimplemented( - "passing flags is not supported yet.", + TokenNode::Operator(op) => Err(ShellError::syntax_error( + "Unexpected operator".tagged(op.tag), + )), + TokenNode::Flag(flag) => Err(ShellError::syntax_error("Unexpected flag".tagged(flag.tag))), + TokenNode::Member(span) => Err(ShellError::syntax_error( + "BUG: Top-level member".tagged(span), + )), + TokenNode::Whitespace(span) => Err(ShellError::syntax_error( + "BUG: Whitespace found during parse".tagged(span), )), - TokenNode::Member(_span) => unreachable!(), - TokenNode::Whitespace(_span) => unreachable!(), TokenNode::Error(error) => Err(*error.item.clone()), TokenNode::Path(path) => baseline_parse_path(path, context, source), } @@ -304,7 +308,11 @@ pub fn baseline_parse_path( TokenNode::Member(span) => span.slice(source), // TODO: Make this impossible - other => unreachable!("{:?}", other), + other => { + return Err(ShellError::syntax_error( + format!("{} in path", other.type_name()).tagged(other.span()), + )) + } } .to_string();