Foundation.Types.Error (foundation v0.1.0)
Pure data structure for Foundation errors.
Contains structured error information with hierarchical codes, context, and recovery suggestions. No business logic - just data.
All errors must have a code, error type, message, and severity. Timestamp defaults to creation time if not provided.
See @type t
for the complete type specification.
Examples
iex> error = Foundation.Types.Error.new([
...> code: 1001,
...> error_type: :validation_failed,
...> message: "Invalid configuration",
...> severity: :high
...> ])
iex> error.error_type
:validation_failed
Summary
Types
High-level error category
Specific error type identifier
Additional context information for the error
Error severity level
Specific error subcategory within a category
Strategy for retrying failed operations
Stack trace information as a list of maps
Functions
Create a new error structure.
Types
@type error_category() :: :config | :system | :data | :external
High-level error category
@type error_code() :: atom()
Specific error type identifier
@type error_context() :: map()
Additional context information for the error
@type error_severity() :: :low | :medium | :high | :critical
Error severity level
@type error_subcategory() :: :structure | :validation | :access | :runtime
Specific error subcategory within a category
@type retry_strategy() :: :no_retry | :immediate | :fixed_delay | :exponential_backoff
Strategy for retrying failed operations
@type stacktrace_info() :: [map()]
Stack trace information as a list of maps
@type t() :: %Foundation.Types.Error{ category: error_category() | nil, code: pos_integer(), context: error_context() | nil, correlation_id: String.t() | nil, error_type: error_code(), message: String.t(), recovery_actions: [String.t()] | nil, retry_strategy: retry_strategy() | nil, severity: error_severity(), stacktrace: stacktrace_info() | nil, subcategory: error_subcategory() | nil, timestamp: DateTime.t() | nil }
Functions
Create a new error structure.
Parameters
fields
: Keyword list containing at minimum:code
,:error_type
,:message
, and:severity
Examples
iex> error = Foundation.Types.Error.new([
...> code: 2001,
...> error_type: :network_timeout,
...> message: "Connection timed out",
...> severity: :medium,
...> retry_strategy: :exponential_backoff
...> ])
iex> error.error_type
:network_timeout
iex> error = Foundation.Types.Error.new([
...> code: 3001,
...> error_type: :data_corruption,
...> message: "Data integrity check failed",
...> severity: :critical,
...> context: %{table: "events", checksum: "abc123"}
...> ])
iex> error.severity
:critical
Raises
KeyError
if required keys are missing