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

Raised at runtime when a key does not exist in the cache.

This exception denotes the cache executed a command, but there was an issue
with the requested key; for example, it doesn't exist.

## Exception fields

See `t:t/0`.

## Error reasons

The `:reason` field can assume a few Nebulex-specific values:

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

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

# `t`

```elixir
@type t() :: %Nebulex.KeyError{
  __exception__: true,
  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 metadata contains the options given to the
    exception excluding the `:reason` and `:key` that are part of
    the exception fields. For example, when raising an exception
    `raise Nebulex.KeyError, key: :test, foo: :bar`, the metadata
    will be `[foo: :bar]`.

---

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