This bounty is no longer available
Web3 DAO | Ethereum Foundation Logo

If there's a CLI parsing problem, then return a Clap:Error, instead of panicking

Organization

Ethereum Foundation

Deadline

N/A

Status

ENDED


INSTRUCTIONS

It's better to have a clean exit. It also makes testing easier.

This means:

  • updating the tests to detect an error from TrinConfig::new_from()
  • replacing all panic! calls with returning a Clap::Error

That probably looks something like:

         match config.web3_transport {
             Web3TransportType::HTTP => match &config.web3_ipc_path[..] {
                 DEFAULT_WEB3_IPC_PATH => {}
-                _ => panic!("Must not supply an ipc path when using http protocol for json-rpc"),
+                _ => {
+                    return clap::Error::with_description(
+                        "Must not supply an ipc path when using http protocol for json-rpc",
+                        clap::ErrorKind::ArgumentConflict,
+                    );
+                }
             },

If we want to get fancier with the error types (and displays), then you might take a look at the example of how .insert() works, which may require a special crate feature. See examples here: https://docs.rs/clap/latest/clap/error/struct.Error.html#method.new