Ops Exceptions¶
Exception hierarchy for the ops (session management) subsystem.
Exception Hierarchy¶
KstlibError
└── OpsError
├── BackendNotFoundError
│ ├── TmuxNotFoundError
│ └── ContainerRuntimeNotFoundError
└── SessionError
├── SessionExistsError
├── SessionNotFoundError
├── SessionStartError
├── SessionAttachError
├── SessionStopError
└── SessionAmbiguousError
Base Exception¶
Backend Not Found Errors¶
- exception kstlib.ops.exceptions.BackendNotFoundError[source]¶
Bases:
OpsError,FileNotFoundErrorBackend binary (tmux, podman, docker) not found in PATH.
Raised when the required backend binary is not installed or not accessible from the current PATH.
- exception kstlib.ops.exceptions.TmuxNotFoundError[source]¶
Bases:
BackendNotFoundErrortmux binary not found in PATH.
Install tmux to use the tmux backend: - macOS: brew install tmux - Ubuntu/Debian: apt install tmux - Windows: Use WSL2 with tmux installed
- exception kstlib.ops.exceptions.ContainerRuntimeNotFoundError[source]¶
Bases:
BackendNotFoundErrorContainer runtime (podman or docker) not found in PATH.
Install podman or docker to use the container backend: - Podman: https://podman.io/getting-started/installation - Docker: https://docs.docker.com/get-docker/
Raised when the required backend binary is not installed or not in PATH.
Session Errors¶
- exception kstlib.ops.exceptions.SessionError[source]¶
Bases:
OpsErrorBase exception for session-related errors.
All session operation exceptions inherit from this class.
- exception kstlib.ops.exceptions.SessionExistsError(name, backend)[source]¶
Bases:
SessionErrorSession or container with this name already exists.
Raised when attempting to create a session with a name that is already in use by another session or container.
- exception kstlib.ops.exceptions.SessionNotFoundError(name, backend)[source]¶
Bases:
SessionErrorSession or container not found.
Raised when attempting to access a session that does not exist.
- exception kstlib.ops.exceptions.SessionStartError(name, backend, reason)[source]¶
Bases:
SessionErrorFailed to start session or container.
Raised when the backend command to create a new session fails.
- exception kstlib.ops.exceptions.SessionAttachError(name, backend, reason)[source]¶
Bases:
SessionErrorFailed to attach to session or container.
Raised when the backend command to attach to a session fails. This can happen if the session is not running or if the terminal is not interactive.
- exception kstlib.ops.exceptions.SessionStopError(name, backend, reason)[source]¶
Bases:
SessionErrorFailed to stop session or container.
Raised when the backend command to stop a session fails.
- exception kstlib.ops.exceptions.SessionAmbiguousError(name, backends)[source]¶
Bases:
SessionErrorSession exists in multiple backends.
Raised when auto-detection finds a session in both tmux and container backends, requiring explicit backend specification.
Raised when auto-detection finds a session in both tmux and container backends.
Use --backend to disambiguate.
Usage Examples¶
from kstlib.ops.exceptions import (
OpsError,
SessionExistsError,
SessionNotFoundError,
TmuxNotFoundError,
ContainerRuntimeNotFoundError,
SessionAmbiguousError,
)
try:
session.start("python app.py")
except TmuxNotFoundError:
print("Install tmux: apt install tmux")
except ContainerRuntimeNotFoundError:
print("Install podman or docker")
except SessionExistsError:
print("Session already running, stop it first")
except SessionAmbiguousError as e:
print(f"Found in {e.backends}, use --backend to specify")
except OpsError as e:
print(f"Ops error: {e}")