-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
sea-orm-cli
errors exit with error code 0
#1342
Comments
I did reproduce this issue and would like to work on it. Implementation
we can use this |
Hey @AngelOnFira, thanks for the report. After some digging I found that we didn't check the status code of the executed command. To handle it properly, we should: // Run migrator CLI on user's behalf
println!("Running `cargo {}`", args.join(" "));
let exit_status = Command::new("cargo").args(args).status()?; // Get the status code
if !exit_status.success() { // Propagate the error if any
return Err("Fail to run migration".into());
} Source code location: sea-orm/sea-orm-cli/src/commands/migrate.rs Lines 67 to 69 in ca20554
I simply thrown an error and it will be handled by sea-orm/sea-orm-cli/src/bin/main.rs Lines 18 to 30 in ca20554
|
Hey @Diwakar-Gupta, thanks for the initiative! Any opinions? |
@billy1624 Apart from Thanks for help. |
Thanks again for contributing! :D |
Thanks for the fix @Diwakar-Gupta! |
Description
When using the CLI, any error returns the status code
0
, which suggests that the command worked properly.Steps to Reproduce
sea-orm-cli migrate; echo "status = $?"
Expected Behavior
sea-orm-cli migrate; echo "status = $?"
should outputstatus = 1
or some other code.Actual Behavior
sea-orm-cli migrate; echo "status = $?"
outputsstatus = 0
, suggesting that the command worked.Reproduces How Often
Always
Versions
Additional Information
This is likely quite easy to fix, it just requires exiting with error code 1 on any error 🙂
My particular use case is I have a script to run migrations in development that looks like the following:
dropdb -U postgres -h localhost -p 5432 -w postgres createdb -U postgres -h localhost -p 5432 -w postgres sea-orm-cli migrate \ && sea-orm-cli generate entity \ -o entity/src/entities \ --expanded-format \ --with-serde both
In this case, I want the script to stop running if the migration failed, since it's easier to debug without the rest of the data from generating entities. The
&&
will only run the second command if the first one exits with a return value of0
.The text was updated successfully, but these errors were encountered: