Error Types¶
Krayne defines a flat exception hierarchy rooted at KrayneError. All exceptions are importable from krayne.errors.
from krayne.errors import (
KrayneError,
ClusterNotFoundError,
ClusterAlreadyExistsError,
ConfigValidationError,
ClusterTimeoutError,
KubeConnectionError,
NamespaceNotFoundError,
)
Exception hierarchy¶
classDiagram
class KrayneError {
Base exception for all Krayne errors
}
class ClusterNotFoundError {
+name: str
+namespace: str
}
class ClusterAlreadyExistsError {
+name: str
+namespace: str
}
class ConfigValidationError {
Wraps Pydantic ValidationError
}
class ClusterTimeoutError {
+name: str
+namespace: str
+timeout: int
}
class KubeConnectionError {
K8s API unreachable
}
class NamespaceNotFoundError {
+namespace: str
}
class SandboxError {
Base for sandbox errors
}
class DockerNotFoundError
class SandboxAlreadyExistsError
class SandboxNotFoundError
KrayneError <|-- ClusterNotFoundError
KrayneError <|-- ClusterAlreadyExistsError
KrayneError <|-- ConfigValidationError
KrayneError <|-- ClusterTimeoutError
KrayneError <|-- KubeConnectionError
KrayneError <|-- NamespaceNotFoundError
KrayneError <|-- SandboxError
SandboxError <|-- DockerNotFoundError
SandboxError <|-- SandboxAlreadyExistsError
SandboxError <|-- SandboxNotFoundError
All exceptions inherit from KrayneError, so you can catch all Krayne errors with a single handler.
Exceptions¶
KrayneError¶
Base exception for all Krayne errors. Catch this to handle any Krayne-specific error.
from krayne.errors import KrayneError
try:
info = create_cluster(config)
except KrayneError as e:
print(f"Krayne error: {e}")
ClusterNotFoundError¶
Raised when an operation targets a cluster that does not exist.
Attributes:
| Attribute | Type | Description |
|---|---|---|
name |
str |
Cluster name |
namespace |
str |
Kubernetes namespace |
Raised by: get_cluster, describe_cluster, scale_cluster, delete_cluster, wait_until_ready
from krayne.errors import ClusterNotFoundError
try:
info = get_cluster("nonexistent")
except ClusterNotFoundError as e:
print(f"Cluster '{e.name}' not found in '{e.namespace}'")
ClusterAlreadyExistsError¶
Raised when creating a cluster with a name that's already in use in the target namespace.
Attributes:
| Attribute | Type | Description |
|---|---|---|
name |
str |
Cluster name |
namespace |
str |
Kubernetes namespace |
Raised by: create_cluster
ConfigValidationError¶
Raised when cluster configuration is invalid — wraps Pydantic ValidationError with a clear message.
Raised by: load_config_from_yaml, ClusterConfig construction
from krayne.errors import ConfigValidationError
try:
config = load_config_from_yaml("bad-config.yaml")
except ConfigValidationError as e:
print(f"Invalid config: {e}")
ClusterTimeoutError¶
Raised when wait_until_ready exceeds the specified timeout.
Attributes:
| Attribute | Type | Description |
|---|---|---|
name |
str |
Cluster name |
namespace |
str |
Kubernetes namespace |
timeout |
int |
Timeout that was exceeded (seconds) |
Raised by: create_cluster (with wait=True), wait_until_ready
KubeConnectionError¶
Raised when the Kubernetes API is unreachable — no valid kubeconfig, network issues, or API server errors.
Raised by: Any SDK function that communicates with Kubernetes.
NamespaceNotFoundError¶
Raised when the specified Kubernetes namespace does not exist.
Attributes:
| Attribute | Type | Description |
|---|---|---|
namespace |
str |
The namespace that was not found |
Raised by: create_cluster
SandboxError¶
Base exception for sandbox-related errors.
DockerNotFoundError¶
Raised when Docker CLI is not available or the Docker daemon is not running.
Raised by: setup_sandbox
SandboxAlreadyExistsError¶
Raised when a sandbox container already exists.
Raised by: setup_sandbox
SandboxNotFoundError¶
Raised when attempting to tear down a sandbox that doesn't exist.
Raised by: teardown_sandbox
Which functions raise which errors¶
| Function | Possible Errors |
|---|---|
create_cluster |
ClusterAlreadyExistsError, NamespaceNotFoundError, ClusterTimeoutError, KubeConnectionError, ConfigValidationError |
get_cluster |
ClusterNotFoundError, KubeConnectionError |
list_clusters |
KubeConnectionError |
describe_cluster |
ClusterNotFoundError, KubeConnectionError |
scale_cluster |
ClusterNotFoundError, KrayneError (worker group not found), KubeConnectionError |
delete_cluster |
ClusterNotFoundError, KubeConnectionError |
wait_until_ready |
ClusterTimeoutError, ClusterNotFoundError, KubeConnectionError |
setup_sandbox |
DockerNotFoundError, SandboxAlreadyExistsError |
teardown_sandbox |
SandboxNotFoundError |