rust-lang-ua / rustcamp

Getting ready for prod
396 stars 74 forks source link

Error handling #94

Open NYBACHOK opened 1 month ago

NYBACHOK commented 1 month ago

Problem to solve

Error handling is omitted from tasks. Panic, Result and Option never get mentioned in idioms chapter nor ecosystem.

Proposal

Add task to 3_ecosystem where it would be required to refactor library code from manual mapping errors to usage of thiserror + write tests with usage of anyhow.

Prior art

https://doc.rust-lang.org/book/ch09-01-unrecoverable-errors-with-panic.html#unrecoverable-errors-with-panic

Alternatives

Error handling mentioned in 5_zero2prod.

Links & references

https://doc.rust-lang.org/book/ch09-01-unrecoverable-errors-with-panic.html#unrecoverable-errors-with-panic

https://docs.rs/thiserror/latest/thiserror/

https://docs.rs/anyhow/latest/anyhow/

NamesMark commented 1 month ago

Agree! I could've sworn it was mentioned, but you are right, it's not here :)

There's multiple levels of error handling and it would be nice to explain this progression from "lazy and fast" to "proper and structured"

Result<(), ()> -> Result<(), String> -> Result<(), CustomError> anyhow/eyre -> thiserror

NYBACHOK commented 1 month ago

Well. This topic may be expanted panic recomendation too

NamesMark commented 1 month ago

The problem I see is that module 3 is already quite heavy. Maybe we can add it to the end of module 2, as it's kinda also a part of the "idioms", and the error crates can be considered secondary to this topic?