kworkflow / patch-hub

patch-hub is a TUI that streamlines the interaction of Linux developers with patches archived on lore.kernel.org
GNU General Public License v2.0
8 stars 6 forks source link

Handle possible unnecessary panics by removing `unwrap()` calls #2

Open davidbtadokoro opened 5 months ago

davidbtadokoro commented 5 months ago

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 of git grep -c 'unwrap()':

src/lore_api_client.rs:1
src/lore_session.rs:6
src/main.rs:3
src/patch.rs:6

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:

davidbtadokoro commented 4 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

davidbtadokoro commented 4 months ago

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.