Repository: nushell/nushell
File: crates/nu-cmd-lang/src/core_commands/error_make.rs (Rust)

Code before:
    ) -> Result<PipelineData, ShellError> {
        let value: Value = call.req(engine_state, stack, 0)?;

        let throw_span = if call.has_flag(engine_state, stack, "unspanned")? {
            None
        } else {
            Some(call.head)
        };

        Err(make_other_error(&value, throw_span))
    }

    fn examples(&self) -> Vec<Example<'_>> {
        vec![
            Example {
                description: "Create a simple custom error",
                example: r#"error make {msg: "my custom error message"}"#,
                result: None,
            },
            Example {
                description: "Create a complex error for a custom command that shows a full `error_struct`",
                example: r#"def foo [x] {
        error make {
            msg: "this is fishy"
            code: "my::error"  # optional error type to use
            label: {  # optional, can be an array of these records as well for multiple labels.
                text: "fish right here"  # Required if $.label exists
                # use (metadata $var).span to get the {start: x end: y} of the variable
                span: (metadata $x).span  # optional
            }
            help: "something to tell the user as help"  # optional
            url: "https://nushell.sh"  # optional
        }
    }"#,
                result: None,
            },
            Example {
                description: "Create a nested error from a try/catch statement with multiple labels",
                example: r#"try {
        error make {msg: "foo" labels: [{text: one} {text: two}]}
    } catch {|err|
        error make {msg: "bar", inner: [($err.json | from json)]}
    }"#,
                result: None,
            },
        ]
    }
}

// Most of the parsing happens with FromValue
#[derive(Debug, Default, Clone, FromValue)]

Review comment (suggestion):
I think we call these lists in nushell vs arrays
```suggestion
            label: {  # optional, can be a list of these records as well for multiple labels.
```

Code after:
        let value: Value = call.req(engine_state, stack, 0)?;

        let throw_span = if call.has_flag(engine_state, stack, "unspanned")? {
            None
        } else {
            Some(call.head)
        };

        Err(make_other_error(&value, throw_span))
    }

    fn examples(&self) -> Vec<Example<'_>> {
        vec![
            Example {
                description: "Create a simple custom error",
                example: r#"error make {msg: "my custom error message"}"#,
                result: None,
            },
            Example {
                description: "Create a complex error for a custom command that shows a full `error_struct`",
                example: r#"def foo [x] {
        error make {
            msg: "this is fishy"
            code: "my::error"  # optional error type to use
            labels: {  # optional, a table or single record
                text: "fish right here"  # Required if $.labels exists
                # use (metadata $var).span to get the {start: x end: y} of the variable
                span: (metadata $x).span  # optional
            }
            help: "something to tell the user as help"  # optional
            url: "https://nushell.sh"  # optional
        }
    }"#,
                result: None,
            },
            Example {
                description: "Create a nested error from a try/catch statement with multiple labels",
                example: r#"try {
        error make {msg: "foo" labels: [{text: one} {text: two}]}
    } catch {|err|
        error make {msg: "bar", inner: [($err.json | from json)]}
    }"#,
                result: None,
            },
        ]
    }
}

// Most of the parsing happens with FromValue
#[derive(Debug, Default, Clone, FromValue, IntoValue)]
struct Error {