mario-eth/soldeer

Commands spawned twice and panic on fail

Closed this issue · 2 comments

A lot of Command::new are spawned twice as .status() and .output() internally spawn a process and wait for it to complete. Only one should be used .output() which also contains .status.

They also panic after completion if an error occurred when spawning the command by using .expect().

Eg.

let mut git_checkout = Command::new("git");
let result = git_checkout
.args(["rev-parse".to_string(), "--verify".to_string(), "HEAD".to_string()])
.env("GIT_TERMINAL_PROMPT", "0")
.current_dir(&path)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
let out = result.output().expect("Getting revision status failed");
let status = result.status().expect("Getting revision output failed");

Note that .status and .output have different output capturing semantics, mainly that .status pipes and .output captures into fields, so this also has to be kept in mind.

Thanks for the comment, i was never happy how i was dealing with status/output, i have to work a bit around it.

beeb commented

Will be fixed in 0.4.0 I guess, this has all been refactored