error make for core
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 | error |
Examples
Create a simple custom error
> error make {msg: "my custom error message"}Create a complex error for a custom command that shows a full error_struct
> 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
}
}Create a nested error from a try/catch statement with multiple labels
> try {
error make {msg: "foo" labels: [{text: one} {text: two}]}
} catch {|err|
error make {msg: "bar", inner: [($err.json | from json)]}
}Notes
Errors are defined by an error_record, which is a record with a specific structure. (*) indicates a required key:
msg: string(*)code: stringlabels: oneof<table, record>help: stringurl: stringinner: table
The labels key allow for placing arrows to points in the code, optionally using span to choose where it points (see metadata). label can be a table (list of records) or a single record. There is an example of both in the examples. Each record has the following structure:
text: string(*)span: record<start: int end: int>
The inner table takes a list of error_struct records, and can be used to have detail the errors that happened in a previous try {} catch {} statement or can be manually created. To use them from a catch statement, see the example below.