AI.Error exception (AI SDK v0.0.1-rc.0)
View SourceStandard error structure for AI module operations.
This module provides consistent error handling across the AI SDK with helpful error messages and context.
Summary
Functions
Converts a standard exception to an AI.Error.
Creates a new error with the given message.
Creates a new error with the given message and reason.
Creates a new error with the given message, reason, and source module.
Wraps an existing error in an AI.Error with additional context.
Types
Functions
@spec from_exception(Exception.t(), module()) :: t()
Converts a standard exception to an AI.Error.
This is useful for standardizing error handling by converting various exception types to our common error format.
Parameters
exception
- The exception to convertsource
- The module that caught the exception
Returns
%AI.Error{}
- A new error struct
Creates a new error with the given message.
Parameters
message
- A string describing the error
Returns
%AI.Error{}
- A new error struct
Creates a new error with the given message and reason.
Parameters
message
- A string describing the errorreason
- The underlying reason or error detail
Returns
%AI.Error{}
- A new error struct with reason
Creates a new error with the given message, reason, and source module.
Parameters
message
- A string describing the errorreason
- The underlying reason or error detailsource
- The module that originated the error
Returns
%AI.Error{}
- A new error struct with reason and source
@spec wrap(Exception.t(), String.t(), module()) :: t()
Wraps an existing error in an AI.Error with additional context.
This is useful for adding context to lower-level errors while preserving the original error information.
Parameters
original_error
- The original error or exceptionmessage
- A string describing the context of the errorsource
- The module wrapping the error
Returns
%AI.Error{}
- A new error struct wrapping the original error