mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 16:05:01 +02:00
Improve def parse errors (#3681)
This commit is contained in:
@ -32,7 +32,10 @@ pub enum ParseErrorReason {
|
||||
Unclosed { delimiter: String, span: Span },
|
||||
|
||||
/// An unexpected internal error has occurred
|
||||
InternalError { message: Spanned<String> },
|
||||
GeneralError {
|
||||
message: String,
|
||||
label: Spanned<String>,
|
||||
},
|
||||
|
||||
/// The parser tried to parse an argument for a command, but it failed for
|
||||
/// some reason
|
||||
@ -83,11 +86,15 @@ impl ParseError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a [ParseErrorReason::InternalError](ParseErrorReason::InternalError)
|
||||
pub fn internal_error(message: Spanned<impl Into<String>>) -> ParseError {
|
||||
/// Construct a [ParseErrorReason::GeneralError](ParseErrorReason::GeneralError)
|
||||
pub fn general_error(
|
||||
message: impl Into<String>,
|
||||
label: Spanned<impl Into<String>>,
|
||||
) -> ParseError {
|
||||
ParseError {
|
||||
reason: ParseErrorReason::InternalError {
|
||||
message: message.item.into().spanned(message.span),
|
||||
reason: ParseErrorReason::GeneralError {
|
||||
message: message.into(),
|
||||
label: label.item.into().spanned(label.span),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -119,11 +126,9 @@ impl From<ParseError> for ShellError {
|
||||
ParseErrorReason::Mismatch { actual, expected } => {
|
||||
ShellError::type_error(expected, actual)
|
||||
}
|
||||
ParseErrorReason::InternalError { message } => ShellError::labeled_error(
|
||||
format!("Internal error: {}", message.item),
|
||||
&message.item,
|
||||
&message.span,
|
||||
),
|
||||
ParseErrorReason::GeneralError { message, label } => {
|
||||
ShellError::labeled_error(&message, &label.item, &label.span)
|
||||
}
|
||||
ParseErrorReason::ArgumentError { command, error } => {
|
||||
ShellError::argument_error(command, error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user