-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix exit codes of binaries #172
base: main
Are you sure you want to change the base?
Conversation
d5a2447
to
0b189f7
Compare
0b189f7
to
86e5f15
Compare
832e894
to
466f8bf
Compare
466f8bf
to
de45de7
Compare
match reset(&mut ui, &config.database).await { | ||
Ok(db_name) => { | ||
ui.outdent(); | ||
ui.success(&format!("Reset database {} successfully.", db_name)); | ||
Ok(()) | ||
} | ||
Err(e) => { | ||
ui.outdent(); | ||
ui.error("Could not reset database!", &e); | ||
Err(e) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super fond of the pattern here, where we log the error manually in every single place.
I think it'd be more robust to do this logging in the main
function above, before exiting with a non-zero code.
I imagine this was originally done to control the message shown to the user. We can achieve the same goal with the following structure:
match reset(&mut ui, &config.database).await { | |
Ok(db_name) => { | |
ui.outdent(); | |
ui.success(&format!("Reset database {} successfully.", db_name)); | |
Ok(()) | |
} | |
Err(e) => { | |
ui.outdent(); | |
ui.error("Could not reset database!", &e); | |
Err(e) | |
} | |
} | |
let outcome = reset(&mut ui, &config.database).await.context("Could not reset the database!"); | |
ui.outdent(); | |
let db_name = outcome?; | |
ui.success(&format!("Reset database {} successfully.", db_name)); | |
Ok(()) |
and in main
:
match cli().await {
Ok(_) => ExitCode::SUCCESS,
Err(e) => {
ui.error(e.to_string(), &e);
ExitCode::FAILURE,
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally ui.error
would just take the error, relying on its Display
implementation, rather than forcing the caller to invoke e.to_string()
, but that can be fixed later.
This fixes the exit codes of the project binaries that currently swallow any errors (they log the errors but always return a successful exit code. That's not critical when working with the binaries in development but leads to bugs like #169 going unnoticed in CI…
The code is quite repetitive now and could use some cleanup eventually.
This also fixes 2 actual errors in the generators which fix CI (which now correctly fails because of these errors).
closes #169