W3cubDocs

/Nushell

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:

input output
nothing any

Examples

Create a simple custom error

>error make {msg:"my custom error message"}
{msg:mycustomerrormessage, debug:GenericError("my custom error message", "", None, None, []), raw:GenericError("my custom error message", "", None, None, [])}

Create a more complex custom error

>error make {
msg:"my custom error message"
label: {
text:"my custom label text"# not mandatory unless $.label exists
start:123# not mandatory unless $.label.end is set
end:456# not mandatory unless $.label.start is set
        }
    }
{msg:mycustomerrormessage, debug:GenericError("my custom error message", "my custom label text", Some(Span { start:123, end:456 }), None, []), raw:GenericError("my custom error message", "my custom label text", Some(Span { start:123, end:456 }), None, [])}

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

>deffoo [x] {
letspan= (metadata$x).span;
error make {
msg:"this is fishy"
label: {
text:"fish right here"
start:$span.start
end:$span.end
            }
        }
    }

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/error_make.html