# libtmux.options.handle_option_error

- **Module:** libtmux.options
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/options.py#L120
- **Page:** https://libtmux.org/reference/py/libtmux-options-handle_option_error/

```
libtmux.options.handle_option_error(error: str) -> type[exc.OptionError]
```

Raise exception if error in option command found.

In tmux 3.0, show-option and show-window-option return invalid option instead of
unknown option. See https://github.com/tmux/tmux/blob/3.0/cmd-show-options.c.

In tmux >2.4, there are 3 different types of option errors:

- unknown option
- invalid option
- ambiguous option

In tmux <2.4, unknown option was the only option.

All errors raised will have the base error of :exc:`exc.OptionError`. So to
catch any option error, use ``except exc.OptionError``.

## Parameters

- `error` (str) — Error response from subprocess call.

## Raises

- `exc.OptionError`
- `exc.UnknownOption`
- `exc.InvalidOption`
- `exc.AmbiguousOption`

## Example

```python
>>> result = server.cmd(
...     'set-option',
...     'unknown-option-name',
... )
```

## Example

```python
>>> bool(isinstance(result.stderr, list) and len(result.stderr))
True
```

## Example

```python
>>> import pytest
>>> from libtmux import exc
```

## Example

```python
>>> with pytest.raises(exc.OptionError):
...     handle_option_error(result.stderr[0])
```
