error make for core

Create an error.

Signature

> error make {flags} (error_struct)

Flags

  • --unspanned, -u: remove the origin label from the error

Parameters

  • error_struct: The error to create.

Input/output types:

inputoutput
nothingany

Examples

Create a simple custom error

> error make {msg: "my custom error message"}
{msg: my custom error message, debug: GenericError { error: "my custom error message", msg: "", span: None, help: None, inner: [] }, raw: GenericError { error: "my custom error message", msg: "", span: None, help: None, inner: [] }}

Create a more complex custom error

> error make {
        msg: "my custom error message"
        label: {
            text: "my custom label text"  # not mandatory unless $.label exists
            # optional
            span: {
                # if $.label.span exists, both start and end must be present
                start: 123
                end: 456
            }
        }
        help: "A help string, suggesting a fix to the user"  # optional
    }
{msg: my custom error message, debug: GenericError { error: "my custom error message", msg: "my custom label text", span: Some(Span { start: 123, end: 456 }), help: Some("A help string, suggesting a fix to the user"), inner: [] }, raw: GenericError { error: "my custom error message", msg: "my custom label text", span: Some(Span { start: 123, end: 456 }), help: Some("A help string, suggesting a fix to the user"), inner: [] }}

Create a custom error for a custom command that shows the span of the argument

> def foo [x] {
        error make {
            msg: "this is fishy"
            label: {
                text: "fish right here"
                span: (metadata $x).span
            }
        }
    }