Open davidbtadokoro opened 5 months ago
Note that we can use unwrap_or_else(<closure>)
to better handle errors in a succinct way. This also makes the output less verbose without the usual starting line thread 'main' panicked at ...
and ending line note: run with RUST_BACKTRACE=1
Note that we can use
unwrap_or_else(<closure>)
to better handle errors in a succinct way.
A complementay idea is to use process::exit(<errno>)
to better exit the program.
Context:
FWIU, the use of the
unwrap()
call is discouraged, as it basically panics if the unwrapping operation fails. IMHO, it is great for quickly development and drafts, but it presents weak points in the application, which can crash at unexpected points. Below, is the output ofgit grep -c 'unwrap()'
:Proposal:
Handle as much as these unnecessary panics as possible. We should at least panic with a custom message... (at very very very least, use
expect()
to convey a custom panic message)Setup:
rustc
version: 1.79.0cargo
version: 1.79.0