rust-cli / book

Documentation on how to use the Rust Programming Language to develop commandline applications
https://rust-cli.github.io/book/index.html
MIT License
816 stars 108 forks source link

Recommend error_stack instead of anyhow #178

Closed SUPERCILEX closed 1 year ago

SUPERCILEX commented 1 year ago

I just migrated and it's much nicer: https://github.com/SUPERCILEX/ftzz/commit/60b73258cc387bb29a643eebc21bcf54af4d21a3. The key difference is that context transitions are backed by the type system. That is, instead of specifying context-free error messages at the call site where they will be duplicated (with .context()), you specify the error message through the Display function of your error type on a context transition (with .change_context()). So .context("Failed to retrieve task result") turns into .change_context(Error::TaskJoin) with #[error("Failed to retrieve subtask results.")] TaskJoin.

epage commented 1 year ago

I think at this time we should wait for it to mature more before re-evaluating which error library we are using. A lot is changing within the error landscape atm with the provider API, termination trait work, etc.

SUPERCILEX commented 1 year ago

Fair enough :+1: