# `AshWorkflow.Errors.UndoNotPermitted`
[🔗](https://github.com/team-alembic/ash_workflow/blob/v0.12.0/lib/ash_workflow/errors/undo_not_permitted.ex#L1)

Raised (or returned) when `undo` is called on a record that cannot be
rewound.

The `reason` field says which rule refused, so callers can branch without
matching on message text:

  * `:undo_not_enabled` — the workflow has no `undo` block.
  * `:no_history` — the record's transition log has no state change to undo.
  * `:not_undoable` — the last state change came from a transition that is
    not marked `undoable?: true`. Automatic steps, timeouts, error paths and
    the initial row all land here.
  * `:window_expired` — the transition is older than the configured `within`.
  * `:different_actor` — `same_actor?` is set and the actor differs from the
    one recorded on the transition.
  * `:no_actor` — `same_actor?` is set and either the caller or the recorded
    transition has no actor.
  * `:stale` — the record moved on between reading the log and writing, so
    the row being undone is no longer the head.

# `reason`

```elixir
@type reason() ::
  :undo_not_enabled
  | :no_history
  | :not_undoable
  | :window_expired
  | :different_actor
  | :no_actor
  | :stale
```

# `exception`

```elixir
@spec exception(opts :: Keyword.t()) :: %AshWorkflow.Errors.UndoNotPermitted{
  __exception__: true,
  bread_crumbs: term(),
  class: term(),
  from_state: term(),
  path: term(),
  reason: term(),
  resource: term(),
  splode: term(),
  stacktrace: term(),
  to_state: term(),
  vars: term()
}
```

Create an `Elixir.AshWorkflow.Errors.UndoNotPermitted` without raising it.

## Keys

- :reason
- :resource
- :from_state
- :to_state

---

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