Flux Error v0.0.1 FluxError exception View Source
Exception module to improve error management.
Link to this section Summary
Functions
Create FluxError.t/0 from an external error.
Log the error, returning the FluxError.t/0.
Extract the error message.
Generate a map/0 based on error data.
Link to this section Types
FluxError exception struct.
The :reason will be used to identify the error message.
The :metadata will be used to inject data into the error message.
Link to this section Functions
from(error, reason \\ :unhandled_error, metadata \\ [])
View Source (since 0.0.1)from(Exception.t() | atom(), atom(), keyword()) :: t()
Create FluxError.t/0 from an external error.
Parameters
error- Anatom/0orException.t/0. Ifatom/0which will be inserted at the metadata:detailkey. IfException.t/0, it will try to get the:reasonvalue, otherwise it will generate aString.t/0from theException.t/0map.reason- Anatom/0identifying the error. Defaults to:unhandled_error.metadata- Akeyword/0with detailed data about the error. Defaults to emptylist/0.
Examples
iex> FluxError.from(:external_failure, :external_module_failed, module: :external)
%FluxError{
reason: :external_module_failed,
metadata: %{
detail: :external_failure,
module: :external
}
}
log(error, stacktrace)
View Source (since 0.0.1)log(Exception.t() | atom(), Exception.stacktrace()) :: t()
Log the error, returning the FluxError.t/0.
It will create a FluxError.t/0 if error is an atom/0 or other
Exception.t/0 using FluxError.from/3.
The log will have two metadata values:
:error_metadata- The inspection of theFluxError.t/0:metadatakey.:error_stacktrace- The error stacktrace.
Parameters
error- Anatom/0orException.t/0.stacktrace- TheException.stacktrace/0of the error.
Examples
iex> try do
...> throw(:failed)
...> catch
...> error -> FluxError.log(error, __STACKTRACE__)
...> end
%FluxError{
reason: :unhandled_error,
metadata: %{
detail: :failed
}
}
message(error)
View Source (since 0.0.1)message(Exception.t() | atom()) :: String.t()
Extract the error message.
It will create a FluxError.t/0 if error is an atom/0 or other
Exception.t/0 using FluxError.from/3.
The message is extracted based on :messages_module app config. Check
FluxError for more information.
Parameters
error- Anatom/0orException.t/0.
Examples
iex> FluxError.message(:failed)
"triggered unhandled error"
Create FluxError.t/0.
Parameters
reason- Anatom/0identifying the error.metadata- Akeyword/0with detailed data about the error. Defaults to emptylist/0.
Examples
iex> FluxError.new(:failed, level: :severe)
%FluxError{
reason: :failed,
metadata: %{
level: :severe
}
}
to_map(error, opts \\ [])
View Source (since 0.0.1)to_map(Exception.t() | atom(), keyword() | nil) :: map()
Generate a map/0 based on error data.
It will create a FluxError.t/0 if error is an atom/0 or other
Exception.t/0 using FluxError.from/3.
Parameters
error- Anatom/0orException.t/0.opts- Akeyword/0with message options. CheckFluxError.Messagesfor more information. Defaults to emptylist/0
Examples
iex> FluxError.to_map(:failed)
%{
error: true,
id: :unhandled_error,
message: "triggered unhandled error",
message_raw: "triggered unhandled error",
metadata: %{
detail: :failed
}
}