From 671eb8e469a1a69c931bdd1d28801c7f0da8b713 Mon Sep 17 00:00:00 2001 From: Diwakar Gupta <39624018+Diwakar-Gupta@users.noreply.github.com> Date: Wed, 18 Jan 2023 15:48:54 +0530 Subject: [PATCH] Fixed sea-orm-cli exit status --- 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 e5e0adc1f..b1a3a1648 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 c7fbaea5c..d59d83792 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()); + } } }