From 727a1c4c7bdbb22d41f97054f5d3e276c658c06a Mon Sep 17 00:00:00 2001 From: Diwakar Gupta <39624018+Diwakar-Gupta@users.noreply.github.com> Date: Thu, 19 Jan 2023 13:10:29 +0530 Subject: [PATCH] Fixed sea-orm-cli exit status (#1402) --- sea-orm-cli/src/commands/generate.rs | 9 +++++---- sea-orm-cli/src/commands/migrate.rs | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sea-orm-cli/src/commands/generate.rs b/sea-orm-cli/src/commands/generate.rs index e5e0adc1f3..b1a3a16484 100644 --- a/sea-orm-cli/src/commands/generate.rs +++ b/sea-orm-cli/src/commands/generate.rs @@ -186,10 +186,11 @@ pub async fn run_generate_command( // Format each of the files for OutputFile { name, .. } in output.files.iter() { - Command::new("rustfmt") - .arg(dir.join(name)) - .spawn()? - .wait()?; + let exit_status = Command::new("rustfmt").arg(dir.join(name)).status()?; // Get the status code + if !exit_status.success() { + // Propagate the error if any + return Err(format!("Fail to format file `{name}`").into()); + } } } } diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index c7fbaea5c6..d59d837920 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -66,7 +66,11 @@ pub fn run_migrate_command( } // Run migrator CLI on user's behalf println!("Running `cargo {}`", args.join(" ")); - Command::new("cargo").args(args).spawn()?.wait()?; + 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()); + } } }