Home Explore Blog CI



nushell

1st chunk of `lang-guide/chapters/types/other_types/error.md`
fd835891ff2107de1e43cfd06e0d89d5adcbe1346e1fa4cd000000010000058d
# Error

<!-- prettier-ignore -->
|     |     |
| --- | --- |
| **_Description:_**    | The data type generated by the `error make` command and other internal commands when an error condition occurs.
| **_Annotation:_**     | `error`                                                                                 
| **_Literal syntax:_** | None
| **_Casts:_**          | `error make` (see below)

## Additional Language Notes

1. While `error` may be used as a type annotation, there is currently no known use-case for doing so, since an `error` value can never be _assigned_ to a variable or custom command parameter. Any error condition results in termination of the current command/expression and will also terminate any assignment expression or custom command. For example:

   ```nu
   > let e: error = (error make --unspanned { msg: "This is an error" })
   Error:   × This is an error

   > $e
   Error: nu::shell::variable_not_found

   × Variable not found
      ╭─[entry #19:1:1]
   1 │ $e
      · ─┬
      ·  ╰── variable not found
      ╰────
   ```

1. The `error` type is also returned from internal Nushell commands to indicate an error condition, but as with assignment, there is no way to use this result.

1. Surrounding code that might potentially throw an `error` with a `try`/`catch {|e|}` block will result in an `$e` variable that is a `record`, not an `error` type.

Title: Error Data Type in Nushell
Summary
This section describes the 'error' data type in Nushell, which is generated when an error condition occurs. It explains the annotation, literal syntax, and casts for the 'error' type. It also highlights that while 'error' can be used as a type annotation, it cannot be assigned to a variable or custom command parameter. Error conditions terminate the current command/expression. The section further notes that internal Nushell commands return the 'error' type to indicate an error, but this result cannot be directly used. Finally, it clarifies that using 'try'/'catch' blocks results in a record, not an error type, being assigned to the error variable.