Skip to content

Commit

Permalink
take review into account, return errors instead of Ok(())
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj authored and Geal committed Aug 18, 2021
1 parent 5d4016a commit 4ce87cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
25 changes: 8 additions & 17 deletions ctl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ pub fn dump_state(mut channel: Channel<CommandRequest,CommandResponse>, timeout:
CommandStatus::Error => {
if json {
print_json_response(&message.message)?;
return Ok(());
} else {
bail!("could not dump proxy state: {}", message.message);
}
bail!("could not dump proxy state: {}", message.message);
},
CommandStatus::Ok => {
if let Some(CommandResponseData::State(state)) = message.data {
Expand Down Expand Up @@ -338,7 +336,7 @@ pub fn upgrade_main(mut channel: Channel<CommandRequest,CommandResponse>,

// Reconnect to the new main
println!("Reconnecting to new main process...");
let mut channel = create_channel(&config).context("could not reconnect to the command unix socket")?;
let mut channel = create_channel(&config).with_context(|| "could not reconnect to the command unix socket")?;

// Do a rolling restart of the workers
let running_workers = workers.iter()
Expand Down Expand Up @@ -437,10 +435,8 @@ pub fn status(mut channel: Channel<CommandRequest,CommandResponse>, json: bool)
CommandStatus::Error => {
if json {
print_json_response(&message.message)?;
Ok(())
} else {
bail!("could not get the worker list: {}", message.message);
}
bail!("could not get the worker list: {}", message.message);
},
CommandStatus::Ok => {
//println!("Worker list:\n{:?}", message.data);
Expand Down Expand Up @@ -587,9 +583,8 @@ pub fn metrics(mut channel: Channel<CommandRequest,CommandResponse>, json: bool)
CommandStatus::Error => {
if json {
print_json_response(&message.message)?;
} else {
bail!("could not stop the proxy: {}", message.message);
}
bail!("could not stop the proxy: {}", message.message);
},
CommandStatus::Ok => {
if &id == &message.id {
Expand Down Expand Up @@ -981,10 +976,9 @@ pub fn reload_configuration(mut channel: Channel<CommandRequest,CommandResponse>
},
CommandStatus::Error => {
if json {
print_json_response(&message.message)
} else {
bail!("could not get the worker list: {}", message.message);
print_json_response(&message.message)?;
}
bail!("could not get the worker list: {}", message.message);
},
CommandStatus::Ok => {
if json {
Expand Down Expand Up @@ -1316,17 +1310,14 @@ pub fn query_application(mut channel: Channel<CommandRequest,CommandResponse>, j
CommandStatus::Error => {
if json {
print_json_response(&message.message)?;
} else {
eprintln!("could not query proxy state: {}", message.message);
}
exit(1);
bail!("could not query proxy state: {}", message.message);
},
CommandStatus::Ok => {
if let Some(needle) = application_id.or(domain) {
if let Some(CommandResponseData::Query(data)) = message.data {
if json {
print_json_response(&data)?;
return Ok(());
return Ok(print_json_response(&data)?);
}

let application_headers = vec!["id", "sticky_session", "https_redirect"];
Expand Down
6 changes: 4 additions & 2 deletions ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod cli;

use std::io;
use structopt::StructOpt;
// use anyhow;

use sozu_command::config::Config;
use sozu_command::channel::Channel;
Expand Down Expand Up @@ -56,7 +55,10 @@ fn main() -> Result<(), anyhow::Error> {
}
},
SubCmd::Upgrade { worker: None } => upgrade_main(channel, &config),
SubCmd::Upgrade { worker: Some(id) } => { upgrade_worker(channel, timeout, id)?; Ok(()) },
SubCmd::Upgrade { worker: Some(id) } => {
upgrade_worker(channel, timeout, id)?;
Ok(())
},
SubCmd::Status{ json } => status(channel, json),
SubCmd::Metrics{ json } => metrics(channel, json),
SubCmd::Logging{ level } => logging_filter(channel, timeout, &level),
Expand Down

0 comments on commit 4ce87cb

Please sign in to comment.