fmterr

Sane error reporting that just works

1 unstable release

0.1.1 Sep 28, 2021
0.1.0 Sep 28, 2021
Download history 110/week @ 2024-07-22 91/week @ 2024-07-29 107/week @ 2024-08-05 147/week @ 2024-08-12 128/week @ 2024-08-19 91/week @ 2024-08-26 108/week @ 2024-09-02 98/week @ 2024-09-09 101/week @ 2024-09-16 139/week @ 2024-09-23 226/week @ 2024-09-30 5/week @ 2024-10-07 89/week @ 2024-10-14 98/week @ 2024-10-21 104/week @ 2024-10-28 91/week @ 2024-11-04

382 downloads per month
Used in 11 crates (4 directly)

MIT license

8KB

fmterr

API Docs Crate Page Top Language

fmterr (pronounced fumpterr obviously!) is a tiny error reporting tool for Rust! If you have an error with a chain of sources and you want to display it to the user without bringing in something like anyhow, fmterr is for you! Just run fmt_err(&err) and you'll get a string error message that displays the source chain nicely for end users.

Usage

You can use fmterr to format any error that implements std::error::Error (basically any error worth its salt) like so:

use fmterr::fmt_err;

// Imagine this is a super-complex error with a nested source
let err = std::io::Error::from(std::io::ErrorKind::NotFound);

let err_str = fmt_err(&err);
println!("{}", err_str);

That'll produce the following if you use a complex error:

Error: first error message

Caused by:
    second error message
    Caused by:
        third error message

Or just this if you use something without a source (with an io::ErrorKind::NotFound):

Error: entity not found

fmterr vs anyhow

Most library applications will use thiserror or the like to create their errors, and then they'll sometimes need a formatting tool. If you use anyhow as a formatting tool, you're basically using a sledgehammer to fix a dent, you just don't need it all! That said, anyhow is fantastic for applications where the rest of its features are needed.

Contributing

We appreciate all kinds of contributions, check out our contributing guidelines for more information! Also, please be sure to follow our code of conduct.

License

See LICENSE.

No runtime deps