Live data from Hacker News

Ergonomic errors in Rust: write fast, debug with ease, handle precisely

gmcgoldr.github.io

1–10 of 28 posts

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#4

This just feels like recreating exceptions, but with more complicated syntax.

I mean broadly that's my entire problem with errors as values: every implementation wastes a ton of syntax trying to make them like exceptions.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#5

How is this different from the even more ergonomic “#[from]” provided by thiserror?

Are all of these proc macros worth it? The compile times for proc macros explode.

I'd rather hand-roll errors than deal with more proc macros. Or better yet, have code gen pay the cost once and never deal with it again.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#8
post #5

How is this different from the even more ergonomic “#[from]” provided by thiserror?

Are all of these proc macros worth it? The compile times for proc macros explode. I'd rather hand-roll errors than deal with more proc macros. Or better yet, have code gen pay the cost once and never deal with it again.

Cognitive load is more expensive than compilation time.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#9
post #5

Earlier quoted context omitted.

Are all of these proc macros worth it? The compile times for proc macros explode. I'd rather hand-roll errors than deal with more proc macros. Or better yet, have code gen pay the cost once and never deal with it again.

Cognitive load is more expensive than compilation time.

Compilation time turns into cognitive load via frustration. Death by a thousand cuts.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#10
OP should really mention that they made stackerror. I couldn’t shake the feeling that this read like an ad for stackerror… and of course the author is the crate writer. This feels somewhat disingenuous without a disclaimer that you wrote the lib and there are other ways.

The general advice is good (except for the awkward use of std error), so for anyone who wants to know what rustaceans are actually using:

- std error when it’s required

- anyhow for flexibly dealing with large classes of errors and rethrowing (often in bin crates or internally in a lib crate ), use anyhow::Context to tag errors

- thiserror for building and generating custom errors (in a lib crate)

- miette/eyre for more advanced features

Watch out for exposing error types in public API because then you are bound to push a breaking change if the upstream does.

Anyhow will probably never have a v2 at this point IMO, the entire Rust ecosystem might have to rev!

[EDIT] dont want to suggest that people avoid stackerror, just want to show what other ecosystem projects there are! stackerror seems to fit the hole of anyhow.

Post reply on HN