flex-error is a lightweight Rust library that uses macros and traits
to switch between different error tracing implementations and no_std. The library currently supports 3 modes via Cargo feature flags:
ErrorDetailis responsible to structured metadata information about a specific error.
ErrorTraceris responsible for tracing error chains and backtraces.
ErrorSourceallows generic conversion of external error types into an ErrorDetail with optional ErrorTrace.
With the separation of concerns,
flex-error allows applications to easily
switch between different error reporting implementations,
anyhow, by implementing
ErrorTracer for the respective reporters.
flex-error defines a
define_error! macro that define custom
types and error types implementing
DefaultTracer type is set globally by the feature flag, so that
application error types do not have to be over-generalized.
The trade off is that it is not possible to use multiple
ErrorTracer implementations at the same time across different crates that
pub extern crate alloc;
define_error! is the main macro that implements a mini DSL to
define error types using
flex-error. The DSL syntax
is as follows:
ErrorSource that only provides error details but do not provide any trace.
This can typically comes from primitive error types that do not implement
Detail type is the error and the returned
ErrorSource that can be used to represent to lack of any error source.
Detail types are
(). This can be used for primitive errors
that are not caused by any error source.
ErrorSource that should implement
other constraints such as
'static, so that it can be traced
by error tracing libraries such as
anyhow. Because these libraries
take ownership of the source error object, the error cannot be extracted as detail
at the same time.
ErrorMessageTracer can be used to generically trace
any error detail that implements
A type implementing
ErrorSource<Trace> is a proxy type that provides the
capability of extracting from an error source of type
returning error detail of type
Self::Detail, and an optional error
tracer of type
An error tracer implements
ErrorTracer<E> if it supports
more sophisticated error tracing for an error type
The contraint for
E depends on the specific error tracer
Type alias to
<Error as ErrorSource<Trace>>::Detail
Type alias to
<Error as ErrorSource<Trace>>::Source
DefaultTracer type alias is used when defining error types
define_error!. With the default Cargo features, or when
eyre_tracer feature is set, this is configured to use the
EyreTracer. Otherwise, it will
be set to AnyhowTracer if
anyhow_tracer feature is set. If neither
anyhow_tracer is set, then
DefaultTracer is set to