# `Nebulex.KeyError`
[🔗](https://github.com/elixir-nebulex/nebulex/blob/v3.1.0/lib/nebulex/exceptions.ex#L169)

Raised, or returned in an `{:error, _}` tuple, when a key does not exist
in the cache.

The cache ran the command, but the requested key was missing or expired.

## Exception fields

See `t:t/0`.

## Error reasons

The `:reason` field can be one of:

  * `:not_found` - the key doesn't exist in the cache.

  * `:expired` - the key doesn't exist in the cache because it expired.

# `t`

```elixir
@type t() :: %Nebulex.KeyError{
  __exception__: term(),
  key: any(),
  metadata: keyword(),
  reason: atom()
}
```

The type for this exception struct.

This exception has the following public fields:

  * `:reason` - the error reason. The two possible reasons are `:not_found`
    or `:expired`. Defaults to `:not_found`.

  * `:key` - the requested key.

  * `:metadata` - the options given to the exception, minus `:reason` and
    `:key`. For example, `raise Nebulex.KeyError, key: :test, foo: :bar`
    gives the metadata `[foo: :bar]`.

---

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