# tmux_scope:run_or_error/2

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_scope.erl#L84
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_scope-run_or_error-2/

```
run_or_error(Function, Cleanup)
-spec run_or_error(fun(() -> Value),
                   fun(() -> ok | {error, term()})) ->
                      Value.
```

Run work and cleanup with `run/2`, returning the callback value directly. Raises {scope_cleanup_failed, Failure} if cleanup fails, retaining both outcomes in `t:failure/0`. With successful cleanup, callback exceptions retain their original reason and stack. Nested raising scopes propagate an inner failure through the outer scope while still attempting outer cleanup.

## Parameters

- `Function` (`fun(() -> Value)`)
- `Cleanup` (`fun(() -> ok | {error, term()})`)

## Guides

Pages that discuss `run_or_error/2`.

- [Ownership and identity](/en/erlang/latest/topics/ownership/)
