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

Handle failed exit codes elegantly #799

Merged
merged 4 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
}

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`{}`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as other PR... I liked the ordering of printouts in the old message more, actually! Feel free to keep the replace logic though.

status,
command_name.replace("\"", "")
Copy link
Member

@xtuc xtuc Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the command_name have quotes? Do we need to add them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why it has quotes, I think it has something to do with the implementation of Display on Command (although I'm not sure). After this the quotes are removed though - I don't think we are the ones that implemented the quotes in the first place.

)
}
Ok(())
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
}

// Ensures that Worker name is valid.
Expand Down