Home Explore Blog CI



nushell

18th chunk of `contributor-book/plugin_protocol_reference.md`
8cd262acc75bf58ed9110a692652d02ef3c59763001eaafe0000000100000faa
            "end": 659965
          }
        }
      }
    ],
    "span": {
      "start": 659950,
      "end": 659966
    }
  }
}
```

### `Block`

A reference to a parsed block of Nushell code, without any captured variables.

| Field    | Type                        |
| -------- | --------------------------- |
| **val**  | unsigned integer (block id) |
| **span** | [`Span`](#span)             |

Example:

```json
{
  "Block": {
    "val": 44500,
    "span": {
      "start": 59400,
      "end": 59480
    }
  }
}
```

### `Closure`

A reference to a parsed block of Nushell code, with variables captured from scope.

| Field    | Type            |
| -------- | --------------- |
| **val**  | `Closure`       |
| **span** | [`Span`](#span) |

`Closure` is defined as:

| Field        | Type                                                          |
| ------------ | ------------------------------------------------------------- |
| **block_id** | unsigned integer                                              |
| **captures** | array of pairs (unsigned integer `var_id`, [`Value`](#value)) |

The plugin **should not** try to inspect the contents of the closure. It is recommended that this is only used as an argument to the [`EvalClosure` engine call](#evalclosure-engine-call). The exact representation of a closure is likely to change in the future to avoid serializing all of the captures.

Example:

```nu
let foo = "bar"
{ || $foo }
```

```json
{
  "Closure": {
    "val": {
      "block_id": 1965,
      "captures": [
        [
          862,
          {
            "String": {
              "val": "bar",
              "span": {
                "start": 660030,
                "end": 660041
              }
            }
          }
        ]
      ]
    },
    "span": {
      "start": 660030,
      "end": 660041
    }
  }
}
```

### `Nothing`

The absence of a value, represented by `null` within Nushell.

| Field    | Type            |
| -------- | --------------- |
| **span** | [`Span`](#span) |

Example:

```nu
null
```

```json
{
  "Nothing": {
    "span": {
      "start": 64550,
      "end": 64554
    }
  }
}
```

### `Error`

An error contained within a value. Trying to operate on the value will most likely cause the error to be forwarded. When writing plugins, error values should typically be handled by returning the error from the command when encountered.

| Field    | Type                            |
| -------- | ------------------------------- |
| **val**  | [`LabeledError`](#labelederror) |
| **span** | [`Span`](#span)                 |

Example:

```nu
error make {
  msg: "foo"
  label: {
    text: "bar"
    span: {
      start: 0
      end: 0
    }
  }
}
```

```json
{
  "Error": {
    "val": {
      "msg": "foo",
      "labels": [
        {
          "text": "bar",
          "span": {
            "start": 0,
            "end": 0
          }
        }
      ],
      "code": null,
      "url": null,
      "help": null,
      "inner": []
    }
  }
}
```

### `Binary`

An array of raw bytes. This is sometimes returned from operations that detect data that isn't valid as UTF-8, but can also be created with `into binary` or binary literals.

| Field    | Type            |
| -------- | --------------- |
| **val**  | byte array      |
| **span** | [`Span`](#span) |

Note that the encoding of byte arrays in [JSON](#json) and [MessagePack](#messagepack) is different - the former uses an array of numbers, but the latter uses the native byte array support.

Example:

```nu
0x[aa bb cc dd]
```

```json
{
  "Binary": {
    "val": [170, 187, 204, 221],
    "span": {
      "start": 659637,
      "end": 659652
    }
  }
}
```

### `CellPath`

Represents a path into subfields of lists, records, and tables.

| Field    | Type            |
| -------- | --------------- |
| **val**  | `CellPath`      |
| **span** | [`Span`](#span) |

`CellPath` is defined as:

| Field       | Type         |
| ----------- | ------------ |
| **members** | `PathMember` |

Title: Nu Value Types: Closure, Nothing, Error, Binary, and CellPath
Summary
This section continues detailing Nu `Value` types, including `Closure` (parsed code block with captured variables and a recommendation against inspecting its contents directly), `Nothing` (absence of a value represented by null), `Error` (an error contained within a value that should be handled by returning the error), `Binary` (array of raw bytes with different encoding in JSON and MessagePack), and `CellPath` (path into subfields of lists, records, and tables). Each type includes field descriptions, Nu examples, and corresponding JSON representations.