Standardized error struct for all LLM providers.
This struct provides a unified format for errors from any provider, with support for standard error types and preservation of provider-specific details.
Error Types
:connection- Network connectivity issues:authentication- API key or auth token problems:rate_limit- Rate limiting/quota exceeded:timeout- Request timeout:provider_error- Provider-specific errors (preserved in details)
Fields
type- One of the standard error types abovemessage- Human-readable error messageprovider- Atom identifying the provider that raised the errordetails- Map with provider-specific error detailstimestamp- DateTime when the error occurred
Example
error = Error.new(:rate_limit,
message: "Rate limit exceeded",
provider: :openai,
details: %{retry_after: 60}
)
Summary
Functions
Creates a new Error struct with the given type and options.
Wraps a provider-specific error into a standardized Error struct.
Types
@type error_type() ::
:connection | :authentication | :rate_limit | :timeout | :provider_error
@type t() :: %LlmCore.LLM.Error{ details: map() | nil, message: String.t() | nil, provider: atom() | nil, timestamp: DateTime.t(), type: error_type() }
Functions
@spec new( error_type(), keyword() ) :: t()
Creates a new Error struct with the given type and options.
Parameters
type- One of::connection,:authentication,:rate_limit,:timeout,:provider_erroropts- Keyword list with optional fields::message,:provider,:details
Examples
iex> Error.new(:connection, message: "Connection refused")
%Error{type: :connection, message: "Connection refused", ...}
iex> Error.new(:rate_limit, message: "Too many requests", provider: :openai, details: %{retry_after: 60})
%Error{type: :rate_limit, ...}
@spec wrap(error_type(), term(), keyword()) :: t()
Wraps a provider-specific error into a standardized Error struct.
This is useful for preserving the original error details while presenting a standardized interface to the rest of the system.
Parameters
type- The error type to assignoriginal_error- The original error from the provider (stored in details)opts- Additional options like:messageand:provider
Examples
iex> original = %{code: "insufficient_quota", message: "Quota exceeded"}
iex> Error.wrap(:provider_error, original, message: "Provider error", provider: :openai)
%Error{type: :provider_error, details: %{code: "insufficient_quota", ...}, ...}