diff --git a/crates/nu-command/src/core_commands/error_make.rs b/crates/nu-command/src/core_commands/error_make.rs index 8735afd451..a8eb6d4aac 100644 --- a/crates/nu-command/src/core_commands/error_make.rs +++ b/crates/nu-command/src/core_commands/error_make.rs @@ -65,14 +65,23 @@ impl Command for ErrorMake { } fn examples(&self) -> Vec { - 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 { _ => None, } } + (Some(Value::String { val: message, .. }), None) => { + Some(ShellError::UnlabeledError(message)) + } _ => None, } } else { diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index b35f8a683d..7851a0bdf4 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -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),