trace-error
Extensions to Rust's error system to automatically include backtraces to the exact location an error originates.
Consider this a more lightweight and less macro-based alternative to error_chain
and similar crates. This crate
does not take care of actually defining the errors and their varieties, but only focuses on a thin container
for holding the errors and a backtrace to their origin.
Trace
and TraceResult
should usually be used in place of Result
using the macros
throw!
, try_throw!
, and try_rethrow!
Although the ?
syntax was just introduced, trace-error
is not yet compatible with it until the Carrier
trait is stabilized. As a result,
all instances of try!
and ?
should be replaced with try_throw!
if you intend to use this crate to its fullest. However, the ?
operator
can be used for Result<_, Trace<E>>
when the return value is also a Result
using Trace<E>
, just because From
is implemented for types for itself.
Additionally, if you must use the Result<T, Trace<E>>
directly instead of immediately returning it, you can use the trace_error!
macro to create it with the desired error value.
If the Trace
being returned in a result does NOT contain the same error type, but they are convertible, use try_rethrow!
to convert the inner error type.
Example:
extern crate trace_error;
use Error;
use ;
use io;
use File;
use TraceResult;
pub type MyResultType<T> = ;