Skip to content

Commit

Permalink
printing the cli errors to standard error stream
Browse files Browse the repository at this point in the history
Added a function that prints the error to the standard error stream and exits the process with a status code of 1, this is to seprate the cli errors from regular output
  • Loading branch information
optimm committed Aug 9, 2023
1 parent bacac07 commit 565eda4
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 565eda4

Please sign in to comment.