mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 18:03:51 +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> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![
|
||||||
description: "Create a custom error for a custom command",
|
Example {
|
||||||
example: r#"def foo [x] {
|
description: "Create a custom error for a custom command",
|
||||||
|
example: r#"def foo [x] {
|
||||||
let span = (metadata $x).span;
|
let span = (metadata $x).span;
|
||||||
error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
|
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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(Some(Value::String { val: message, .. }), None) => {
|
||||||
|
Some(ShellError::UnlabeledError(message))
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
} else {
|
} 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}"))]
|
#[diagnostic(help("{1}"))]
|
||||||
LabeledError(String, String),
|
LabeledError(String, String),
|
||||||
|
|
||||||
|
#[error("{0}")]
|
||||||
|
UnlabeledError(String),
|
||||||
|
|
||||||
#[error("{1}")]
|
#[error("{1}")]
|
||||||
#[diagnostic()]
|
#[diagnostic()]
|
||||||
OutsideSpannedLabeledError(#[source_code] String, String, String, #[label("{2}")] Span),
|
OutsideSpannedLabeledError(#[source_code] String, String, String, #[label("{2}")] Span),
|
||||||
|
Loading…
Reference in New Issue
Block a user