# libtmux.exc.SocketPathTooLong

- **Module:** libtmux.exc
- **Package:** libtmux
- **Language:** Python
- **Kind:** exception
- **Source:** https://github.com/tmux-python/libtmux/blob/efdbb5637666b166358772ecc737b3807beab21e/src/libtmux/exc.py#L389
- **Bases:** [`LibTmuxException`](/en/py/latest/reference/libtmux-exc-libtmuxexception/)
- **Page:** https://libtmux.org/en/py/latest/reference/libtmux-exc-socketpathtoolong/

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.

## Examples

```python
>>> 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:

```python
>>> 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:

```python
>>> 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 :exc:`LibTmuxException` hierarchy, so ``except LibTmuxException`` catches it:

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

## Members

### Other members

- [`__init__`](/en/py/latest/reference/libtmux-exc-socketpathtoolong-__init__/) (method)

## Inherited members

- [`__str__`](/en/py/latest/reference/libtmux-exc-socketpathtoolong-__str__/) (method), inherited from `libtmux.exc.LibTmuxException`: Render with optional ``"<subcommand>: …"`` prefix.
