Home Explore Blog CI



nushell

23th chunk of `contributor-book/plugin_protocol_reference.md`
0704ee924c941d7771d8b2e756f92c04f5e0ed8fb4e9e85e0000000100000dff
| **code**   | string?               | A unique machine- and search-friendly code that can be matched against, e.g. `nu::shell::missing_config_value` |
| **url**    | string?               | A URL that links to additional information about the error.                                                    |
| **help**   | string?               | Additional help for the error, usually a hint about what the user might try.                                   |
| **inner**  | `LabeledError` array? | Additional errors referenced by the error, possibly the cause(s) of this error.                                |

Most of the fields are not required - only `msg` must be present. `ErrorLabel` (in the `labels` array) is as follows:

| Field    | Type            | Description                                                 |
| -------- | --------------- | ----------------------------------------------------------- |
| **text** | string          | The message for the label.                                  |
| **span** | [`Span`](#span) | The span in the source code that the label should point to. |

::: tip
When reading the Rust source code for the `nu-plugin` crates, many places where `LabeledError` is specified here are actually represented as `ShellError` in that implementation. However, `ShellError` always serializes as if it were `LabeledError`, so the difference between the two can be ignored within the protocol.
:::

Example:

```json
{
  "msg": "A really bad error occurred",
  "labels": [
    {
      "text": "I don't know, but it's over nine thousand!",
      "span": {
        "start": 9001,
        "end": 9007
      }
    }
  ],
  "code": "my_plugin::bad::really_bad",
  "url": "https://example.org/my_plugin/error/bad/really_bad.html",
  "help": "you can solve this by not doing the bad thing",
  "inner": [
    {
      "msg": "The bad thing"
    }
  ]
}
```

### `Config`

[Documentation](https://docs.rs/nu-protocol/latest/nu_protocol/struct.Config.html)

This struct describes the configuration of Nushell. It is quite large and frequently changing, so please refer to the Rust documentation if there is anything you need from it.

### `Ordering`

[Documentation](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html)

We serialize the Rust `Ordering` type as literal strings, for example:

```js
'Less'; // left hand side is less than right hand side
'Equal'; // both values are equal
'Greater'; // left hand side is greater than right hand side
```

### `Operator`

[Documentation](https://docs.rs/nu-protocol/latest/nu_protocol/ast/enum.Operator.html)

Serialized with serde's default enum representation. Examples:

```js
{ "Math": "Append" }           // ++   Math(Append)
{ "Bits": "BitOr" }            // |    Bits(BitOr)
{ "Comparison": "RegexMatch" } // =~   Comparison(RegexMatch)
```

### `SignalAction`

The `SignalAction` enum is used to specify actions that the plugin should take in response to signals from the engine.

| Variant       | Description                                                                            |
| ------------- | -------------------------------------------------------------------------------------- |
| `Interrupt`   | Indicates an interrupt signal (e.g., Ctrl+C) was received. Plugins should pause, stop, or end their operation. |
| `Reset`       | Indicates a reset signal from the engine’s `reset_signals` function. Plugins should reset any internal signal states. |

This enum can be used in conjunction with `register_signal_handler` to perform specific tasks when each signal type is received.

Title: LabeledError Example, Config, Ordering, Operator, and SignalAction Details
Summary
This section provides an example of the `LabeledError` structure and clarifies its representation in Rust source code. It also describes the `Config` struct, the `Ordering` type (represented as strings), the `Operator` type (using serde's default enum representation), and the `SignalAction` enum, detailing their variants and usage in handling signals from the engine.