Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.16 KB

README.md

File metadata and controls

41 lines (29 loc) · 1.16 KB

bigerror 🍅🍆🥒

Errors should be composed of reusable parts to make readability consistent.

example

What if handling an error also produces an error?

code:

bigerror/src/lib.rs

Lines 822 to 838 in 51686e4

fn error_in_error_handling() {
crate::init_colour();
fn output() -> Result<usize, Report<ConversionError>> {
"NaN"
.parse::<usize>()
.map_err(ConversionError::from::<&str, usize>)
.map_err(|e| match "More NaN".parse::<u32>() {
Ok(attachment) => e.attach_printable(attachment),
Err(attachment_err) => e
.attach_printable(ParseError)
.attach_kv("val: \"More Nan\"", attachment_err),
})
}
let _ = output().change_context(MyError).unwrap();
}

command (try it yourself):

$ cargo test -- test::error_in_error_handling --nocapture

output:

image

extra

If just is installed: just printerr-all to visualize all unit test errors

-- This error crate is intended to
-- enhance error-stack:
-- https://hash.dev/blog/announcing-error-stack
-- error-stack `is_fantastic && does_things.in(|_a| functional(approach))` but
-- `error_stack::Report::change_context` can make code noisy when used often
--
-- ...so why not auto implement a bunch of `From<Error> for MyError`?
-- and provide fundamental building blocks such as `bigerror::NotFound`
-- to express common causes for errors and imply correlation?
CREATE CRATE IF NOT EXISTS
  bigerror (
    error BIGERROR NOT NULL,
);