Skip to content

Commit

Permalink
Merge pull request containers#31 from lsm5/use-expect
Browse files Browse the repository at this point in the history
replace calls to unwrap with expect
  • Loading branch information
openshift-merge-robot authored Oct 15, 2021
2 parents 254cbcb + c63ea39 commit dbc60f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/commands/setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Configures the given network namespace with provided specs
use std::path::PathBuf;
use clap::{self, Clap};
use crate::network;
use clap::{self, Clap};
use log::debug;
use std::path::PathBuf;

#[derive(Clap, Debug)]
pub struct Setup {
Expand All @@ -20,11 +20,14 @@ impl Setup {
}

pub fn exec(&self, input_file: PathBuf) {

debug!("{:?}", "Setting up...");

//TODO: Can we be more safe while converting PathBuf to string
let _network_options = match network::types::NetworkOptions::load(&input_file.into_os_string().into_string().unwrap()) {
let _network_options = match network::types::NetworkOptions::load(
&input_file
.into_os_string()
.into_string()
.expect("Failed to convert PathBuf to string during network setup"),
) {
Ok(opts) => opts,
Err(e) => panic!("{}", e),
};
Expand Down
12 changes: 8 additions & 4 deletions src/commands/teardown.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;
use clap::{self, Clap};
use crate::network;
use clap::{self, Clap};
use log::debug;
use std::path::PathBuf;

#[derive(Clap, Debug)]
pub struct Teardown {
Expand All @@ -19,10 +19,14 @@ impl Teardown {
}

pub fn exec(&self, input_file: PathBuf) {

debug!("{:?}", "Tearing down..");
//TODO: Can we be more safe while converting PathBuf to string
let _network_options = match network::types::NetworkOptions::load(&input_file.into_os_string().into_string().unwrap()) {
let _network_options = match network::types::NetworkOptions::load(
&input_file
.into_os_string()
.into_string()
.expect("Failed to convert PathBuf to string during network teardown"),
) {
Ok(opts) => opts,
Err(e) => panic!("{}", e),
};
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate env_logger;

use std::path::PathBuf;
use clap::{crate_version, Clap};
use std::path::PathBuf;

use netavark::commands::setup;
use netavark::commands::teardown;
Expand Down Expand Up @@ -32,8 +32,12 @@ fn main() {
let opts = Opts::parse();

match opts.subcmd {
SubCommand::Setup(setup) => setup.exec(opts.file.unwrap()),
SubCommand::Teardown(teardown) => teardown.exec(opts.file.unwrap()),
SubCommand::Setup(setup) => {
setup.exec(opts.file.expect("Failed to read file for network setup"))
}
SubCommand::Teardown(teardown) => {
teardown.exec(opts.file.expect("Failed to read file for network teardown"))
}
}
}

Expand Down

0 comments on commit dbc60f5

Please sign in to comment.