mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
agent-ctl: Remove some unwrap and expect calls
Replace some `unwrap()` and `expect()` calls with code to return the error to the caller. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
35db75baa1
commit
09abcd4dc6
@ -153,8 +153,9 @@ fn connect(name: &str, global_args: clap::ArgMatches) -> Result<()> {
|
||||
.collect();
|
||||
}
|
||||
|
||||
// Cannot fail as a default has been specified
|
||||
let log_level_name = global_args.value_of("log-level").unwrap();
|
||||
let log_level_name = global_args
|
||||
.value_of("log-level")
|
||||
.ok_or_else(|| anyhow!("cannot get log level"))?;
|
||||
|
||||
let log_level = logging::level_name_to_slog_level(log_level_name).map_err(|e| anyhow!(e))?;
|
||||
|
||||
@ -166,10 +167,10 @@ fn connect(name: &str, global_args: clap::ArgMatches) -> Result<()> {
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let hybrid_vsock_port: u64 = args
|
||||
let hybrid_vsock_port = args
|
||||
.value_of("hybrid-vsock-port")
|
||||
.ok_or("Need Hybrid VSOCK port number")
|
||||
.map(|p| p.parse::<u64>().unwrap())
|
||||
.ok_or_else(|| anyhow!("Need Hybrid VSOCK port number"))?
|
||||
.parse::<u64>()
|
||||
.map_err(|e| anyhow!("VSOCK port number must be an integer: {:?}", e))?;
|
||||
|
||||
let bundle_dir = args.value_of("bundle-dir").unwrap_or("").to_string();
|
||||
@ -215,7 +216,7 @@ fn real_main() -> Result<()> {
|
||||
.long("log-level")
|
||||
.short("l")
|
||||
.help("specific log level")
|
||||
.default_value(logging::slog_level_to_level_name(DEFAULT_LOG_LEVEL).unwrap())
|
||||
.default_value(logging::slog_level_to_level_name(DEFAULT_LOG_LEVEL).map_err(|e| anyhow!(e))?)
|
||||
.possible_values(&logging::get_log_levels())
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
|
Loading…
Reference in New Issue
Block a user