mirror of
https://github.com/nushell/nushell.git
synced 2024-12-26 00:50:03 +01:00
Allow 'error make' to make simple errors (#4881)
* Allow 'error make' to make simple errors * Add example
This commit is contained in:
parent
d5f23ab592
commit
e6a5011fdb
@ -65,14 +65,23 @@ impl Command for ErrorMake {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Create a custom error for a custom command",
|
||||
example: r#"def foo [x] {
|
||||
vec![
|
||||
Example {
|
||||
description: "Create a custom error for a custom command",
|
||||
example: r#"def foo [x] {
|
||||
let span = (metadata $x).span;
|
||||
error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
|
||||
}"#,
|
||||
result: None,
|
||||
}]
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Create a simple custom error for a custom command",
|
||||
example: r#"def foo [x] {
|
||||
error make {msg: "this is fishy"}
|
||||
}"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,6 +114,9 @@ fn make_error(value: &Value) -> Option<ShellError> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
(Some(Value::String { val: message, .. }), None) => {
|
||||
Some(ShellError::UnlabeledError(message))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
|
@ -315,6 +315,9 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
#[diagnostic(help("{1}"))]
|
||||
LabeledError(String, String),
|
||||
|
||||
#[error("{0}")]
|
||||
UnlabeledError(String),
|
||||
|
||||
#[error("{1}")]
|
||||
#[diagnostic()]
|
||||
OutsideSpannedLabeledError(#[source_code] String, String, String, #[label("{2}")] Span),
|
||||
|
Loading…
Reference in New Issue
Block a user