travisbrown / cancel-culture

Tools for fighting abuse on Twitter
Mozilla Public License 2.0
409 stars 30 forks source link

add the `displaydoc` crate with `thiserror` to simplify error cases #19

Closed cosmicexplorer closed 3 years ago

cosmicexplorer commented 3 years ago

Description

The error cases in this project are thoughtfully separated and easy to understand. However, since being advised over in signalapp/libsignal-client#296, I have learned about the joy and wonder of displaydoc + thiserror to auto-generate std::error::Error as well as std::fmt::Display implementations, with a minimum of additional boilerplate.

Incidentally, in the process of making this change, I removed the blanket From<std::io::Error> impl and found a few places were catching an io error elsewhere--so we also add an additional Error::StdinError case to handle std::io::Error outside of parsing keys.toml.

Resources

Feel free to reject any or all of this change. I hope that it helps to clarify some code in a useful way. ^_^

cosmicexplorer commented 3 years ago

I'm currently also adding this to the wayback crate and elsewhere, but that requires more changes (adding file paths to I/O errors is particularly useful, but also changes maybe 20 more lines of code) and I'm about to fall asleep, so this is a nice compartmentalized change that we can use to agree on whether we like this change to error cases.

Again, I'm totally fine if this doesn't seem useful to you ^_^ I loved this codebase, it's fantastically nice code and very easy to follow.

travisbrown commented 3 years ago

Thanks! This looks good to me!