Unified error types for Candil.
All functions in Candil return {:ok, result} or {:error, Candil.Error.t}
to provide consistent error handling across the library.
Summary
Functions
Create an auth error (401/403).
Create a backend-unavailable error (the Backend behaviour module is not loaded, or its implementation raised at startup).
Create a cancellation error (caller cancelled via
Candil.Llm.cancel/1).
Creates a context overflow error when messages exceed the model's context window.
Creates an engine exited error with exit code.
Creates an error for an engine that is not running.
Build a typed error directly from an HTTP status code and body.
See http_error/2.
Creates an HTTP error with status and optional body.
Creates an invalid API key error.
Creates an invalid request error with a message.
Returns the error kind (alias for reason/0).
Creates an error for a model that was not found.
Creates a provider not found error.
Creates a rate limiting error.
Create a server error (5xx).
Creates a startup timeout error.
Creates a timeout error.
Wraps a raw error reason into a Candil.Error.
Types
@type reason() ::
:model_not_found
| :engine_not_running
| :http_error
| :server_error
| :auth_error
| :timeout
| :rate_limited
| :invalid_api_key
| :context_overflow
| :provider_not_found
| :invalid_request
| :engine_exited
| :startup_timeout
| :circuit_open
| :execution_failed
| :backend_unavailable
| :cancelled
Functions
@spec auth_error(pos_integer(), term()) :: t()
Create an auth error (401/403).
Create a cancellation error (caller cancelled via
Candil.Llm.cancel/1).
@spec context_overflow(non_neg_integer(), non_neg_integer()) :: t()
Creates a context overflow error when messages exceed the model's context window.
@spec engine_exited(non_neg_integer(), atom()) :: t()
Creates an engine exited error with exit code.
@spec engine_not_running(Candil.Engine.alias() | term()) :: t()
Creates an error for an engine that is not running.
@spec from_http_status(non_neg_integer(), term()) :: t()
Build a typed error directly from an HTTP status code and body.
See http_error/2.
@spec http_error(pos_integer(), term()) :: t()
Creates an HTTP error with status and optional body.
If status matches a known category (401/403 → :auth_error,
429 → :rate_limited, 5xx → :server_error, 404 with a model
reference → :model_not_found), the reason is normalized to the
specific kind. Otherwise it stays :http_error.
@spec invalid_api_key() :: t()
Creates an invalid API key error.
Creates an invalid request error with a message.
Returns the error kind (alias for reason/0).
Provided so callers can write error.kind instead of error.reason
if they prefer. The struct field is still named :reason for
source-compatibility with existing call-sites.
@spec model_not_found(Candil.Model.alias() | term()) :: t()
Creates an error for a model that was not found.
@spec provider_not_found(Candil.Provider.alias() | term()) :: t()
Creates a provider not found error.
Creates a rate limiting error.
@spec server_error(pos_integer(), term()) :: t()
Create a server error (5xx).
Creates a startup timeout error.
Creates a timeout error.
Wraps a raw error reason into a Candil.Error.