AI.Error exception (AI SDK v0.0.1-rc.0)

View Source

Standard 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

t()

@type t() :: %AI.Error{
  __exception__: true,
  message: String.t(),
  reason: term() | nil,
  source: module() | nil
}

Functions

from_exception(exception, source)

@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 convert
  • source - The module that caught the exception

Returns

  • %AI.Error{} - A new error struct

new(message)

@spec new(String.t()) :: t()

Creates a new error with the given message.

Parameters

  • message - A string describing the error

Returns

  • %AI.Error{} - A new error struct

new(message, reason)

@spec new(String.t(), term()) :: t()

Creates a new error with the given message and reason.

Parameters

  • message - A string describing the error
  • reason - The underlying reason or error detail

Returns

  • %AI.Error{} - A new error struct with reason

new(message, reason, source)

@spec new(String.t(), term(), module()) :: t()

Creates a new error with the given message, reason, and source module.

Parameters

  • message - A string describing the error
  • reason - The underlying reason or error detail
  • source - The module that originated the error

Returns

  • %AI.Error{} - A new error struct with reason and source

wrap(original_error, message, 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 exception
  • message - A string describing the context of the error
  • source - The module wrapping the error

Returns

  • %AI.Error{} - A new error struct wrapping the original error