Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

error make for core

Create an error.

Signature

> error make {flags} (error_struct)

Flags

  • --unspanned, -u: remove the labels from the error

Parameters

  • error_struct: The error to create.

Input/output types:

inputoutput
nothingerror
stringerror
recorderror

Examples

Create a simple, default error

> error make

Create a simple error from a string

> error make 'my error message'

Create a simple error from an error_struct record

> error make {msg: 'my error message'}

A complex error utilizing spans and inners

> def foo [x: int, y: int] {
        let z = $x + $y
        error make {
            msg: "an error for foo just occurred"
            labels: [
                {text: "one" span: (metadata $x).span}
                {text: "two" span: (metadata $y).span}
            ]
            help: "some help for the user"
            inner: [
                {msg: "an inner error" labels: [{text: "" span: (metadata $y).span}]}
            ]
        }
    }

Chain errors using a pipeline

> try {error make "foo"} catch {error make "bar"}

Chain errors using arguments (note the extra command in catch)

> try {
        error make "foo"
    } catch {|err|
        print 'We got an error that will be chained!'
        error make {msg: "bar" inner: [$err]}
    }

Notes

Use either as a command with an error_struct or string as an input. The error_struct is detailed below:

  • msg: string (required)
  • code: string
  • labels: table<error_label>
  • help: string
  • url: string
  • inner: table<error_struct>
  • src: src_record

The error_label should contain the following keys:

  • text: string
  • span: record<start: int end: int>

External errors (referencing external sources, not the default nu spans) are created using the src column with the src_record record. This only changes where the labels are placed. For this, the code key is ignored, and will always be nu::shell::outside. Errors cannot use labels that reference both inside and outside sources, to do that use an inner error.

  • name: string - name of the source
  • text: string - the raw text to place the spans in
  • path: string - a file path to place the spans in

Errors can be chained together using the inner key, and multiple spans can be specified to give more detailed error outputs.

If a string is passed it will be the msg part of the error_struct.

Errors can also be chained using try {} catch {}, allowing for related errors to be printed out more easily. The code block for catch passes a record of the try block's error into the catch block, which can be used in error make either as the input or as an argument. These will be added as inner errors to the most recent error make.