Skip to content

resolve_socket_path

Resolve the first existing socket path from an optional candidate list. The client constructors use this function when no explicit socket_path is supplied.

Resolve the first existing socket path from the candidate list.

Parameters:

Name Type Description Default
candidates Iterable[Path] | None

Optional paths to check in order. When omitted, use Herdr's standard environment and default socket resolution order.

None
session str | None

Optional named session used to build the candidate path when candidates is omitted.

None

Returns:

Type Description
Path

The first existing Unix socket path.

Raises:

Type Description
FileNotFoundError

If none of the candidate paths exists.

Example
from herdr_client import resolve_socket_path

socket_path = resolve_socket_path(session="work")
print(socket_path)
Source code in src/herdr_client/transport.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def resolve_socket_path(
    candidates: Iterable[Path] | None = None,
    session: str | None = None,
) -> Path:
    """Resolve the first existing socket path from the candidate list.

    Args:
        candidates: Optional paths to check in order. When omitted, use Herdr's
            standard environment and default socket resolution order.
        session: Optional named session used to build the candidate path when
            ``candidates`` is omitted.

    Returns:
        The first existing Unix socket path.

    Raises:
        FileNotFoundError: If none of the candidate paths exists.

    Example:
        ```python
        from herdr_client import resolve_socket_path

        socket_path = resolve_socket_path(session="work")
        print(socket_path)
        ```
    """
    resolved_candidates = (
        list(candidates)
        if candidates is not None
        else DEFAULT_SOCKET_CANDIDATES(session)
    )
    for candidate in resolved_candidates:
        if candidate.exists():
            return candidate
    searched = ", ".join(str(candidate) for candidate in resolved_candidates)
    raise FileNotFoundError(f"No herdr socket found; checked: {searched}")