# libtmux.common.raise_if_stderr

- **Module:** libtmux.common
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/common.py#L245
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-common-raise_if_stderr/

```
libtmux.common.raise_if_stderr(
    proc: tmux_cmd, subcommand: str
) -> None
```

Raise :exc:`LibTmuxException` tagged with the tmux subcommand on stderr.

Centralizes the ``if proc.stderr: raise exc.LibTmuxException(proc.stderr)``
pattern scattered across the wrappers. Tags the exception with the
originating tmux subcommand so downstream consumers (e.g. libtmux-mcp's
``handle_tool_errors``) keep the "which tmux command failed" context.

## Examples

```python
>>> from libtmux.common import raise_if_stderr
>>> from libtmux import exc
>>> proc = session.cmd("display-message", "-p", "#{session_id}")
>>> raise_if_stderr(proc, "display-message")  # no stderr → no raise
```

## Parameters

- `proc` (`tmux_cmd`): Result of a :meth:`Server.cmd` / :meth:`Session.cmd` / etc. call.
- `subcommand` (`str`): The tmux subcommand the wrapper invoked, e.g. ``"last-window"``,
``"swap-pane"``. Surfaces in ``str(exc)`` as a ``"<subcommand>: …"``
prefix.

## Raises

- [`LibTmuxException`](/en/py/stable/reference/libtmux-exc-libtmuxexception/): When ``proc.stderr`` is non-empty.
