The aim of this library is to support writing command line programs in Rust by simplifying error handling in program code.
It introduces Problem type which can be used on high level APIs for which error handling boils down to:
- reporting error message (e.g. log with
error!macro), - aborting program on error other than a bug (e.g. using
panic!macro), - ignoring error.
Goals
- Simplifying type signatures around error handling to one type so they compose easily
- Allow errors to bubble up easily by elimination of life times in error types
- Produce user friendly error messages with
Displayformatting - Support multiple ways to add context to error message
- Easy to work with existing types and patterns
- No performance impact on
Okpath
Non Goals
- Providing ability to match on particular error variant to facilitate handling of error condition
- High performance of
Errpath - e.g. zero allocation SyncandSendcompatibility
Example
Implicit conversion to Problem type and context message.
use *;
let result = foo.problem_while;
assert_eq!;
Handling fatal errors with panic and Problem::or_failed_to.
use *;
use format_panic_to_stderr;
format_panic_to_stderr;
let _s = foo.or_failed_to; // Fatal error: Panicked in src/lib.rs:464:25: Failed to create a string due to: invalid utf-8 sequence of 1 bytes from index 2
For more examples see crate documentation at docs.rs.