# `Tezex.Michelson.EncodeError`
[🔗](https://github.com/objkt-com/tezex/blob/v6.0.0/lib/michelson/encode_error.ex#L1)

A value that doesn't fit its Michelson type, returned by `Tezex.Michelson.encode/2`
and raised by `Tezex.Michelson.encode!/2`.

- `reason`: what went wrong, see `t:reason/0`.
- `path`: where in the value, root first. A segment is a field or branch name
  (string), a tuple or list position (integer), `:left` / `:right` for an `or`
  branch without a name, `{:key, k}` for a map key or set element, and
  `{:value, k}` for the value under map key `k`.
- `value`: the value that was rejected (`nil` for a missing field).
- `expected`: what would have been accepted there.

# `reason`

```elixir
@type reason() ::
  :invalid_value
  | :missing_field
  | :unknown_field
  | :duplicate_field
  | :unknown_branch
  | :ambiguous_branch
  | :duplicate_key
  | :not_comparable
  | :not_passable
  | :unsupported_type
```

# `segment`

```elixir
@type segment() ::
  String.t()
  | non_neg_integer()
  | :left
  | :right
  | {:key, term()}
  | {:value, term()}
```

# `t`

```elixir
@type t() :: %Tezex.Michelson.EncodeError{
  __exception__: term(),
  expected: String.t(),
  path: [segment()],
  reason: reason(),
  value: term()
}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
