# `Mailglass.EventLedgerImmutableError`
[🔗](https://github.com/szTheory/mailglass/blob/v0.1.0/lib/mailglass/errors/event_ledger_immutable_error.ex#L1)

Raised when the `mailglass_events` append-only immutability trigger fires.

The event ledger is append-only by design (D-15 project-level, D-06 phase-level).
A Postgres `BEFORE UPDATE OR DELETE` trigger on `mailglass_events` raises
`SQLSTATE 45A01` for every mutation attempt. `Mailglass.Repo.transact/1`
translates that `%Postgrex.Error{}` into this struct so callers pattern-match
a mailglass-owned error, never the raw Postgrex one.

## Types

- `:update_attempt` — an UPDATE statement hit the trigger
- `:delete_attempt` — a DELETE statement hit the trigger

Never retryable — an immutability violation is a bug in the calling code.

See `Mailglass.Error` for the shared contract and `docs/api_stability.md`
for the locked `:type` atom set.

# `t`

```elixir
@type t() :: %Mailglass.EventLedgerImmutableError{
  __exception__: true,
  cause: Exception.t() | nil,
  context: %{required(atom()) =&gt; term()},
  message: String.t(),
  pg_code: String.t(),
  type: :update_attempt | :delete_attempt
}
```

# `__types__`
*since 0.1.0* 

```elixir
@spec __types__() :: [atom()]
```

Returns the closed set of valid `:type` atoms. Tested against `docs/api_stability.md`.

# `new`
*since 0.1.0* 

```elixir
@spec new(
  atom(),
  keyword()
) :: t()
```

Build a `Mailglass.EventLedgerImmutableError` struct.

## Options

- `:cause` — the underlying `%Postgrex.Error{}` (kept out of JSON output).
- `:context` — a map of non-PII metadata. `:pg_code` is propagated into
  the `:pg_code` struct field.
- `:pg_code` — the SQLSTATE code; defaults to `"45A01"`.

---

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