Candil.Error exception (Candil v2.0.0)

Copy Markdown View Source

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

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.

Creates an error for an HTTP error with status and optional body.

Creates an invalid API key error.

Creates an invalid request error with a message.

Creates an error for a model that was not found.

Creates a provider not found error.

Creates a rate limiting error.

Creates a startup timeout error.

Creates a timeout error.

Wraps a raw error reason into a Candil.Error.

Types

reason()

@type reason() ::
  :model_not_found
  | :engine_not_running
  | :http_error
  | :timeout
  | :rate_limited
  | :invalid_api_key
  | :context_overflow
  | :provider_not_found
  | :invalid_request
  | :engine_exited
  | :startup_timeout
  | term()

t()

@type t() :: %Candil.Error{__exception__: true, context: map(), reason: reason()}

Functions

context_overflow(token_count, max_tokens)

@spec context_overflow(non_neg_integer(), non_neg_integer()) :: t()

Creates a context overflow error when messages exceed the model's context window.

engine_exited(code, model_alias)

@spec engine_exited(non_neg_integer(), atom()) :: t()

Creates an engine exited error with exit code.

engine_not_running(engine_alias)

@spec engine_not_running(Candil.Engine.alias() | term()) :: t()

Creates an error for an engine that is not running.

http_error(status, body \\ nil)

@spec http_error(pos_integer(), term()) :: t()

Creates an error for an HTTP error with status and optional body.

invalid_api_key()

@spec invalid_api_key() :: t()

Creates an invalid API key error.

invalid_request(message)

@spec invalid_request(binary()) :: t()

Creates an invalid request error with a message.

model_not_found(model_alias)

@spec model_not_found(Candil.Model.alias() | term()) :: t()

Creates an error for a model that was not found.

provider_not_found(provider_alias)

@spec provider_not_found(Candil.Provider.alias() | term()) :: t()

Creates a provider not found error.

rate_limited(retry_after \\ nil)

@spec rate_limited(term()) :: t()

Creates a rate limiting error.

startup_timeout(model_alias)

@spec startup_timeout(atom()) :: t()

Creates a startup timeout error.

timeout(context \\ %{})

@spec timeout(term()) :: t()

Creates a timeout error.

wrap(reason)

@spec wrap(term()) :: t()

Wraps a raw error reason into a Candil.Error.