mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Better generic errors for plugins (and perhaps scripts) (#12236)
# Description This makes `LabeledError` much more capable of representing close to everything a `miette::Diagnostic` can, including `ShellError`, and allows plugins to generate multiple error spans, codes, help, etc. `LabeledError` is now embeddable within `ShellError` as a transparent variant. This could also be used to improve `error make` and `try/catch` to reflect `LabeledError` exactly in the future. Also cleaned up some errors in existing plugins. # User-Facing Changes Breaking change for plugins. Nicer errors for users.
This commit is contained in:
@ -2,7 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
||||
Category, Example, LabeledError, PipelineData, Record, ShellError, Signature, Span,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -258,13 +259,10 @@ fn make_other_error(value: &Value, throw_span: Option<Span>) -> ShellError {
|
||||
}
|
||||
|
||||
// correct return: everything present
|
||||
ShellError::GenericError {
|
||||
error: msg,
|
||||
msg: text,
|
||||
span: Some(Span::new(span_start as usize, span_end as usize)),
|
||||
help,
|
||||
inner: vec![],
|
||||
}
|
||||
let mut error =
|
||||
LabeledError::new(msg).with_label(text, Span::new(span_start as usize, span_end as usize));
|
||||
error.help = help;
|
||||
error.into()
|
||||
}
|
||||
|
||||
fn get_span_sides(span: &Record, span_span: Span, side: &str) -> Result<i64, ShellError> {
|
||||
|
Reference in New Issue
Block a user