Closed cosmicexplorer closed 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.
Thanks! This looks good to me!
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-generatestd::error::Error
as well asstd::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 additionalError::StdinError
case to handlestd::io::Error
outside of parsingkeys.toml
.Resources
thiserror
(the#[from]
and#[source]
annotations are described here. They basically perform the delegation forstd::error::Error
and/or implementFrom<>
)displaydoc
Feel free to reject any or all of this change. I hope that it helps to clarify some code in a useful way. ^_^