Snakepit.Error (Snakepit v0.6.10)
View SourceStructured error type for Snakepit operations.
Provides detailed context for debugging cross-language and distributed system issues.
Error Categories
:worker- Worker process errors (not found, crashed, etc.):timeout- Operation timed out:python_error- Exception from Python code:grpc_error- gRPC communication error:validation- Input validation error:pool- Pool management error
Examples
# Create a worker error
error = Snakepit.Error.worker_error("Worker not found", %{worker_id: "w1"})
# Create a Python exception error
error = Snakepit.Error.python_error(
"ValueError",
"Invalid input",
traceback_string,
%{function: "process_data"}
)
# Pattern match in your code
case Snakepit.execute("command", %{}) do
{:ok, result} -> result
{:error, %Snakepit.Error{category: :timeout}} -> retry()
{:error, %Snakepit.Error{category: :python_error} = error} ->
Logger.error("Python error: #{error.message}")
Logger.debug("Traceback: #{error.python_traceback}")
{:error, error} -> {:error, error}
end
Summary
Functions
Creates a gRPC communication error.
Creates a pool management error.
Creates a Python exception error with traceback.
Creates a timeout error.
Creates a validation error.
Creates a worker-related error.
Types
Functions
Creates a gRPC communication error.
Examples
iex> Snakepit.Error.grpc_error(:unavailable, "Service unavailable")
%Snakepit.Error{
category: :grpc_error,
message: "Service unavailable",
grpc_status: :unavailable
}
Creates a pool management error.
Examples
iex> Snakepit.Error.pool_error("Pool not found", %{pool_name: :test})
%Snakepit.Error{category: :pool, message: "Pool not found", details: %{pool_name: :test}}
Creates a Python exception error with traceback.
Examples
iex> Snakepit.Error.python_error("ValueError", "Invalid input", "Traceback...")
%Snakepit.Error{
category: :python_error,
message: "ValueError: Invalid input",
python_traceback: "Traceback...",
details: %{exception_type: "ValueError"}
}
Creates a timeout error.
Examples
iex> Snakepit.Error.timeout_error("Request timed out", %{timeout_ms: 5000})
%Snakepit.Error{category: :timeout, message: "Request timed out", details: %{timeout_ms: 5000}}
Creates a validation error.
Examples
iex> Snakepit.Error.validation_error("Invalid field", %{field: "user_id"})
%Snakepit.Error{category: :validation, message: "Invalid field", details: %{field: "user_id"}}
Creates a worker-related error.
Examples
iex> Snakepit.Error.worker_error("Worker crashed")
%Snakepit.Error{category: :worker, message: "Worker crashed", details: %{}}
iex> Snakepit.Error.worker_error("Worker not found", %{worker_id: "w1"})
%Snakepit.Error{category: :worker, message: "Worker not found", details: %{worker_id: "w1"}}