Allow 'error make' to make simple errors (#4881)

* Allow 'error make' to make simple errors

* Add example
This commit is contained in:
JT
2022-03-20 16:25:45 +13:00
committed by GitHub
parent d5f23ab592
commit e6a5011fdb
2 changed files with 20 additions and 5 deletions

View File

@ -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 {