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.
Display
formattingOk
pathErr
path - e.g. zero allocationSync
and Send
compatibilityImplicit conversion to Problem
type and context message.
```rust,skt-problem
use problem::prelude::*;
fn foo() -> Result
let result = foo().problem_while("creating string");
asserteq!(result.unwraperr().to_string(), "while creating string got error caused by: invalid utf-8 sequence of 1 bytes from index 2"); ```
Handling fatal errors with panic and Problem::or_failed_to
.
```rust,shouldpanic,skt-problem
use problem::prelude::*;
use problem::formatpanictostderr;
formatpanicto_stderr();
fn foo() -> Result
let s = foo().orfailed_to("create a string"); // 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.