# libtmux._internal.env.check_socket_path_length

- **Module:** libtmux._internal.env
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/efdbb5637666b166358772ecc737b3807beab21e/src/libtmux/_internal/env.py#L165
- **Page:** https://libtmux.org/en/py/latest/reference/libtmux-_internal-env-check_socket_path_length/

```
libtmux._internal.env.check_socket_path_length(
    socket_path: StrPath,
    socket_name: str | None = None,
    env_var: str | None = None,
    env_value: str | None = None,
) -> None
```

Raise if *socket_path* is too long to be a UNIX socket address.

A tmux socket is a UNIX domain socket, so its path has to fit in
:data:`SOCKET_PATH_MAX_BYTES` -- a filesystem that accepts the path says
nothing about whether a socket can be bound at it. Length is counted in
*bytes*, as the kernel counts it, so a non-ASCII path runs out sooner than
its character count suggests.

## Parameters

- `socket_path` (`StrPath`): Path to measure.
- `socket_name` (`str | None`): Socket name *socket_path* was resolved from, when it was resolved
rather than passed in. Recorded on the exception so the message can say
the length was inherited from ``$TMUX_TMPDIR``.
  Default: `None`.
- `env_var` (`str | None`): Environment variable the socket directory came from, when one did.
Recorded on the exception so the message can name it.
  Default: `None`.
- `env_value` (`str | None`): What that variable held, so the caller can see what to shorten.
  Default: `None`.

## Raises

- [`SocketPathTooLong`](/en/py/latest/reference/libtmux-exc-socketpathtoolong/): When *socket_path* exceeds :data:`SOCKET_PATH_MAX_BYTES` bytes.

## Examples

```python
>>> from libtmux._internal.env import (
...     check_socket_path_length,
...     SOCKET_PATH_MAX_BYTES,
... )
>>> check_socket_path_length("/tmp/tmux-1000/default")
```

```python
>>> try:
...     check_socket_path_length("/tmp/" + "d" * 200 + "/sock")
... except exc.SocketPathTooLong as e:
...     (e.length, e.limit == SOCKET_PATH_MAX_BYTES)
(210, True)
```

A name that resolves somewhere too deep reports the name too. The path is measured as given -- whether tmux would really bind there is settled by :func:`resolve_socket_path` before this is called:

```python
>>> deep = pathlib.Path("/tmp/" + "d" * 200) / "tmux-1000" / "dev"
>>> try:
...     check_socket_path_length(deep, socket_name="dev")
... except exc.SocketPathTooLong as e:
...     e.socket_name
'dev'
```
