Exceptions

libtmux exceptions.

libtmux.exc

libtmux.exc._match_env_subcommand(token)
function[source]
function[source]
libtmux.exc._match_env_subcommand(token)

Classify token if it names an -e or set-environment command.

Parameters:

token (str)

Return type:

tuple[str, frozenset[str]] | None

libtmux.exc._skip_global_flags(argv, idx)
function[source]
function[source]
libtmux.exc._skip_global_flags(argv, idx)

Advance idx past leading client-level tmux flags.

Parameters:
Return type:

int

libtmux.exc._redact_env_flag_segment(out, start, end, value_flags)
function[source]
function[source]
libtmux.exc._redact_env_flag_segment(out, start, end, value_flags)

Mask -e NAME=value (standalone or clustered) in out[start:end].

Parameters:
Return type:

None

libtmux.exc._redact_set_env_segment(out, start, end)
function[source]
function[source]
libtmux.exc._redact_set_env_segment(out, start, end)

Mask the value argument of set-environment in out[start:end].

Parameters:
Return type:

None

libtmux.exc._redact_env_values(argv)
function[source]
function[source]
libtmux.exc._redact_env_values(argv)

Return argv with environment values masked and their names kept.

Parameters:

argv (Sequence[str])

Return type:

list[str]

libtmux.exc._escape_control_chars(value)
function[source]
function[source]
libtmux.exc._escape_control_chars(value)

Escape ASCII and C1 control characters onto a single printable line.

Parameters:

value (str)

Return type:

str

libtmux.exc._format_command(argv)
function[source]
function[source]
libtmux.exc._format_command(argv)

Render argv onto one line with environment values masked.

Parameters:

argv (Sequence[str])

Return type:

str

libtmux.exc._format_query(query)
function[source]
function[source]
libtmux.exc._format_query(query)

Render a QueryList.get() lookup back as key=value text.

Examples

>>> from libtmux.exc import _format_query
>>> _format_query({"pane_id": "%0"})
"pane_id='%0'"
>>> _format_query({"window_name": "shared", "window_index": "1"})
"window_name='shared', window_index='1'"
>>> _format_query({})
''
Parameters:

query (Mapping[str, Any])

Return type:

str

exception libtmux.exc.LibTmuxException
exception[source]
exception[source]
exception libtmux.exc.LibTmuxException

Bases: Exception

Base Exception for libtmux Errors.

Parameters:
  • *args (object) – Forwarded to Exception.

  • subcommand (str, optional) –

    The tmux subcommand that produced this error (e.g. "last-window"). When set, __str__() formats as "<subcommand>: <stderr>" so downstream consumers see which tmux command failed.

    Added in version 0.57.

exception libtmux.exc.DeprecatedError
exception[source]
exception[source]
exception libtmux.exc.DeprecatedError

Bases: LibTmuxException

Raised when a deprecated function, method, or parameter is used.

This exception provides clear guidance on what to use instead.

Parameters:
  • deprecated (str) – The name of the deprecated API (e.g., “Pane.resize_pane()”)

  • replacement (str) – The recommended replacement API to use instead

  • version (str) – The version when the API was deprecated (e.g., “0.28.0”)

exception libtmux.exc.TmuxSessionExists
exception[source]
exception[source]
exception libtmux.exc.TmuxSessionExists

Bases: LibTmuxException

Session does not exist in the server.

exception libtmux.exc.TmuxCommandNotFound
exception[source]
exception[source]
exception libtmux.exc.TmuxCommandNotFound

Bases: LibTmuxException

Application binary for tmux not found or not executable.

exception libtmux.exc.TmuxTransportError
exception[source]
exception[source]
exception libtmux.exc.TmuxTransportError

Bases: LibTmuxException

Transport failed to communicate with the tmux client or server.

Added in version 0.70.0.

exception libtmux.exc.TmuxCommandTimeout
exception[source]
exception[source]
exception libtmux.exc.TmuxCommandTimeout

Bases: TmuxTransportError, TimeoutError

A tmux client invocation exceeded its wall-clock timeout.

The spawned tmux client is killed with SIGKILL and reaped before this exception is raised. Commands already accepted by the tmux server, as well as running panes and the server itself, are not rolled back or stopped. Environment assignments in the formatted message have their values masked to *** and control characters escaped onto a single line.

Parameters:
  • argv (Sequence[str]) – Command vector of the timed-out tmux client.

  • timeout (float) – Timeout in seconds that the command exceeded.

Examples

>>> from libtmux import exc
>>> err = exc.TmuxCommandTimeout(["tmux", "wait-for", "build-done"], 0.5)
>>> err.argv
('tmux', 'wait-for', 'build-done')
>>> err.cmd
['tmux', 'wait-for', 'build-done']
>>> err.timeout
0.5
>>> str(err)
'tmux command timed out after 0.5s: tmux wait-for build-done'
>>> issubclass(exc.TmuxCommandTimeout, exc.LibTmuxException)
True
>>> issubclass(exc.TmuxCommandTimeout, TimeoutError)
True

Added in version 0.70.0.

exception libtmux.exc.NotInsideTmux
exception[source]
exception[source]
exception libtmux.exc.NotInsideTmux

Bases: LibTmuxException

Raised when the process is not running inside a tmux pane.

tmux exports $TMUX and $TMUX_PANE into the environment of every pane it spawns. The from_env() family raises this when one of them is missing or malformed – i.e. the caller is not (or is no longer) recognizable as a tmux pane’s child process.

Parameters:
  • variable (str, optional) – Name of the offending environment variable, e.g. "TMUX".

  • reason (str) – Why it is unusable. Defaults to "unset or empty".

  • *args (object) – Forwarded to LibTmuxException.

Examples

>>> from libtmux import exc
>>> str(exc.NotInsideTmux("TMUX"))
'Not inside a tmux pane: $TMUX is unset or empty'
>>> str(exc.NotInsideTmux("TMUX_PANE", reason="not a pane id"))
'Not inside a tmux pane: $TMUX_PANE is not a pane id'
>>> str(exc.NotInsideTmux())
'Not inside a tmux pane'

It is part of the LibTmuxException hierarchy:

>>> issubclass(exc.NotInsideTmux, exc.LibTmuxException)
True

Added in version 0.62.

exception libtmux.exc.SocketPathTooLong
exception[source]
exception[source]
exception libtmux.exc.SocketPathTooLong

Bases: LibTmuxException

A tmux socket path is longer than a UNIX socket address can hold.

sun_path in struct sockaddr_un is a fixed-size buffer, so a path over the platform’s limit can never be connected to, whatever the filesystem allows. tmux says error connecting to <path> (File name too long), which names the path but not how far over it is, nor which variable made it that long.

The overrun is usually inherited rather than typed: a deep pytest tmp_path, an XDG runtime dir, a nested worktree, a long $TMUX_TMPDIR. So the message adds the numbers tmux leaves out – how many bytes over the limit, and where the length came from.

Parameters:
  • socket_path (str or os.PathLike) – The path that does not fit. Measured in bytes, as the kernel does.

  • limit (int) – Bytes available for a socket path on this platform.

  • *args (object) – Forwarded to LibTmuxException.

  • socket_name (str, optional) – Set when the path was resolved from a socket name rather than passed in, in which case the length came from $TMUX_TMPDIR.

  • env_var (str, optional) – Environment variable the directory came from, when one did.

  • env_value (str, optional) – What that variable held, so the caller can see what to shorten.

Examples

>>> from libtmux import exc
>>> print(exc.SocketPathTooLong("/tmp/" + "d" * 120 + "/sock", 107))
Socket path is 130 bytes, 23 over the 107 byte limit: /tmp/ddd...

A path nobody typed says where it came from, and what to shorten:

>>> print(
...     exc.SocketPathTooLong(
...         "/tmp/" + "d" * 120 + "/tmux-1000/dev",
...         107,
...         socket_name="dev",
...         env_var="TMUX_TMPDIR",
...         env_value="/tmp/" + "d" * 120,
...     )
... )
Socket path for socket_name='dev' is 139 bytes, 32 over the 107 byte
limit: /tmp/ddd... Inherited from $TMUX_TMPDIR: shorten it, or pass a
socket_path under a shorter directory.

The numbers and the provenance are readable, for a caller that would rather format its own message:

>>> e = exc.SocketPathTooLong("/tmp/" + "d" * 120 + "/sock", 107)
>>> e.length, e.over, e.limit, e.env_var
(130, 23, 107, None)

It is part of the LibTmuxException hierarchy, so except LibTmuxException catches it:

>>> issubclass(exc.SocketPathTooLong, exc.LibTmuxException)
True

Added in version 0.63.

exception libtmux.exc.ObjectDoesNotExist
exception[source]
exception[source]
exception libtmux.exc.ObjectDoesNotExist

Bases: LibTmuxException

A lookup expected one object and matched none.

Raised by get() when nothing matches and no default was passed.

Parameters:
  • *args (object) – A ready-made message, forwarded to LibTmuxException. When omitted, the message is built from query.

  • query (Mapping, optional) – The lookup that matched nothing, e.g. {"pane_id": "%99"}. Annotated object so a subclass can forward **kwargs.

Examples

>>> from libtmux import exc
>>> str(exc.ObjectDoesNotExist())
'No objects found'

A lookup that named what it wanted says so:

>>> str(exc.ObjectDoesNotExist(query={"pane_id": "%99"}))
"No objects found: pane_id='%99'"

It is part of the LibTmuxException hierarchy, so except LibTmuxException catches it:

>>> issubclass(exc.ObjectDoesNotExist, exc.LibTmuxException)
True

Changed in version 0.62: Re-based on LibTmuxException and given a message.

exception libtmux.exc.MultipleObjectsReturned
exception[source]
exception[source]
exception libtmux.exc.MultipleObjectsReturned

Bases: LibTmuxException

A lookup expected one object and matched several.

Raised by get(). Unlike ObjectDoesNotExist, a default does not suppress it: a default is a stand-in for an object that is absent, and an ambiguous lookup is not an absent one. Silently answering with one of several equally valid matches is how you end up driving the wrong pane.

On a server-wide collection, several matches for a single id is ordinary and means the window is linked into more than one session. See When one window is in two sessions for what to do about it.

Parameters:
  • *args (object) – A ready-made message, forwarded to LibTmuxException. When omitted, the message is built from count and query.

  • count (int, optional) – How many objects the lookup matched.

  • query (Mapping, optional) – The lookup that matched them, e.g. {"pane_id": "%0"}. Both are annotated object so a subclass can forward **kwargs.

Examples

>>> from libtmux import exc
>>> str(exc.MultipleObjectsReturned())
'Multiple objects returned'

A lookup that matched too much reports how much, and for what:

>>> str(exc.MultipleObjectsReturned(count=2, query={"pane_id": "%0"}))
"Multiple objects returned (2): pane_id='%0'"

It is part of the LibTmuxException hierarchy, so except LibTmuxException catches it:

>>> issubclass(exc.MultipleObjectsReturned, exc.LibTmuxException)
True

Added in version 0.62: Added to libtmux.exc as a LibTmuxException subclass with a message.

exception libtmux.exc.TmuxObjectDoesNotExist
exception[source]
exception[source]
exception libtmux.exc.TmuxObjectDoesNotExist

Bases: ObjectDoesNotExist

tmux has no object with the id that was asked for.

Examples

>>> from libtmux import exc
>>> str(exc.TmuxObjectDoesNotExist())
'Could not find object'
>>> str(
...     exc.TmuxObjectDoesNotExist(
...         obj_key="pane_id",
...         obj_id="%99",
...         list_cmd="list-panes",
...         list_extra_args=("-t", "%99"),
...     )
... )
"Could not find pane_id=%99 for list-panes ('-t', '%99')"
exception libtmux.exc.VersionTooLow
exception[source]
exception[source]
exception libtmux.exc.VersionTooLow

Bases: LibTmuxException

Raised if tmux below the minimum version to use libtmux.

exception libtmux.exc.BadSessionName
exception[source]
exception[source]
exception libtmux.exc.BadSessionName

Bases: LibTmuxException

Disallowed session name for tmux (empty, contains periods or colons).

exception libtmux.exc.OptionError
exception[source]
exception[source]
exception libtmux.exc.OptionError

Bases: LibTmuxException

Root error for any error involving invalid, ambiguous or bad options.

exception libtmux.exc.UnknownOption
exception[source]
exception[source]
exception libtmux.exc.UnknownOption

Bases: OptionError

Option unknown to tmux show-option(s) or show-window-option(s).

exception libtmux.exc.UnknownColorOption
exception[source]
exception[source]
exception libtmux.exc.UnknownColorOption

Bases: UnknownOption

Unknown color option.

exception libtmux.exc.InvalidOption
exception[source]
exception[source]
exception libtmux.exc.InvalidOption

Bases: OptionError

Option invalid to tmux.

exception libtmux.exc.AmbiguousOption
exception[source]
exception[source]
exception libtmux.exc.AmbiguousOption

Bases: OptionError

Option that could potentially match more than one.

exception libtmux.exc.WaitTimeout
exception[source]
exception[source]
exception libtmux.exc.WaitTimeout

Bases: LibTmuxException

Function timed out without meeting condition.

exception libtmux.exc.VariableUnpackingError
exception[source]
exception[source]
exception libtmux.exc.VariableUnpackingError

Bases: LibTmuxException

Error unpacking variable.

exception libtmux.exc.PaneError
exception[source]
exception[source]
exception libtmux.exc.PaneError

Bases: LibTmuxException

Any type of pane related error.

exception libtmux.exc.PaneNotFound
exception[source]
exception[source]
exception libtmux.exc.PaneNotFound

Bases: PaneError

Pane not found.

exception libtmux.exc.WindowError
exception[source]
exception[source]
exception libtmux.exc.WindowError

Bases: LibTmuxException

Any type of window related error.

exception libtmux.exc.MultipleActiveWindows
exception[source]
exception[source]
exception libtmux.exc.MultipleActiveWindows

Bases: WindowError

Multiple active windows.

exception libtmux.exc.NoActiveWindow
exception[source]
exception[source]
exception libtmux.exc.NoActiveWindow

Bases: WindowError

No active window found.

exception libtmux.exc.NoWindowsExist
exception[source]
exception[source]
exception libtmux.exc.NoWindowsExist

Bases: WindowError

No windows exist for object.

exception libtmux.exc.AdjustmentDirectionRequiresAdjustment
exception[source]
exception[source]
exception libtmux.exc.AdjustmentDirectionRequiresAdjustment

Bases: LibTmuxException, ValueError

If adjustment_direction is set, adjustment must be set.

exception libtmux.exc.WindowAdjustmentDirectionRequiresAdjustment
exception[source]
exception[source]
exception libtmux.exc.WindowAdjustmentDirectionRequiresAdjustment

Bases: WindowError, AdjustmentDirectionRequiresAdjustment

ValueError for libtmux.Window.resize_window().

exception libtmux.exc.PaneAdjustmentDirectionRequiresAdjustment
exception[source]
exception[source]
exception libtmux.exc.PaneAdjustmentDirectionRequiresAdjustment
exception libtmux.exc.RequiresDigitOrPercentage
exception[source]
exception[source]
exception libtmux.exc.RequiresDigitOrPercentage

Bases: LibTmuxException, ValueError

Requires digit (int or str digit) or a percentage.