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()); + } } }