Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #799 from cloudflare/avery/exit-codes
Browse files Browse the repository at this point in the history
Handle failed exit codes elegantly
  • Loading branch information
ashleygwilliams authored Oct 24, 2019
2 parents 68035e2 + 545298d commit 3f8ae7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
12 changes: 2 additions & 10 deletions src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::process::Command;

use crate::commands::validate_worker_name;
use crate::settings::target::{Manifest, Site, TargetType};
use crate::terminal::{emoji, message};
use crate::{commands, install};

pub fn generate(
Expand Down Expand Up @@ -36,18 +35,11 @@ pub fn run_generate(name: &str, template: &str) -> Result<(), failure::Error> {
let command = command(name, binary_path, &args);
let command_name = format!("{:?}", command);

commands::run(command, &command_name)?;
Ok(())
commands::run(command, &command_name)
}

fn command(name: &str, binary_path: PathBuf, args: &[&str]) -> Command {
let msg = format!(
"{} Generating a new worker project with name '{}'...",
emoji::SHEEP,
name
);

message::working(&msg);
log::info!("Generating a new worker project with name '{}'", name);

let mut c = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
Expand Down
15 changes: 6 additions & 9 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::process::Command;

use log::info;

pub mod build;
pub mod config;
pub mod generate;
Expand All @@ -26,19 +24,18 @@ pub use whoami::whoami;

/// Run the given command and return its stdout.
pub fn run(mut command: Command, command_name: &str) -> Result<(), failure::Error> {
info!("Running {:?}", command);
log::info!("Running {:?}", command);

let status = command.status()?;

if status.success() {
Ok(())
} else {
if !status.success() {
failure::bail!(
"failed to execute `{}`: exited with {}",
command_name,
status
"command exited with {}\n`{}`",
status,
command_name.replace("\"", "")
)
}
Ok(())
}

// Ensures that Worker name is valid.
Expand Down

0 comments on commit 3f8ae7a

Please sign in to comment.