Skip to content

Commit

Permalink
Merge pull request #225 from optimm/exception-handling/teos-cli
Browse files Browse the repository at this point in the history
Fix error handling in CLI
  • Loading branch information
sr-gi authored Aug 10, 2023
2 parents bacac07 + 565eda4 commit 6cbc8df
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions teos/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ use teos::protos::private_tower_services_client::PrivateTowerServicesClient;
use teos_common::appointment::Locator;
use teos_common::UserId;

/// Prints the cli error to standard error and exits the process
fn handle_error<T: std::fmt::Display>(error: T) {
eprintln!("{}", error);
std::process::exit(1);
}

#[tokio::main]
async fn main() {
let opt = Opt::from_args();
Expand Down Expand Up @@ -80,10 +86,10 @@ async fn main() {
Ok(appointments) => {
println!("{}", pretty_json(&appointments.into_inner()).unwrap())
}
Err(status) => println!("{}", status.message()),
Err(status) => handle_error(status.message()),
}
}
Err(e) => println!("{e}"),
Err(e) => handle_error(e),
};
}
Command::GetTowerInfo => {
Expand All @@ -106,10 +112,10 @@ async fn main() {
Ok(response) => {
println!("{}", pretty_json(&response.into_inner()).unwrap())
}
Err(status) => println!("{}", status.message()),
Err(status) => handle_error(status.message()),
}
}
Err(e) => println!("{e}"),
Err(e) => handle_error(e),
};
}
Command::Stop => {
Expand Down

0 comments on commit 6cbc8df

Please sign in to comment.