Skip to content

Commit

Permalink
Clean-up/improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Feb 6, 2024
1 parent ba5d66b commit 794ed2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ members = [
"my-project",
"xtask",
]
resolver = "2"
4 changes: 2 additions & 2 deletions examples/demo/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<()> {

match opt {
Opt::Watch { command, watch } => {
log::info!("starting to watch");
log::info!("Starting to watch");
if !command.is_empty() {
let mut it = command.iter();

Expand All @@ -42,7 +42,7 @@ fn main() -> Result<()> {

let mut sleep = Command::new("bash");
sleep.arg("-c");
sleep.arg("echo sleeping for 10 seconds...; sleep 10; echo sleep ended");
sleep.arg("set -e; echo sleeping for 10 seconds...; sleep 10; echo sleep ended");

watch.run([check, test, sleep])?;
}
Expand Down
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,30 @@ impl Watch {
let mut current_child = current_child.clone();
let mut commands = commands.clone();
thread::spawn(move || {
commands.spawn(move |res| match res {
let mut status = ExitStatus::default();
commands.spawn(|res| match res {
Err(err) => {
log::error!("command failed: {err}");
log::error!("Could not execute command: {err}");
false
}
Ok(child) => {
log::trace!("new child: {}", child.id());
current_child.replace(child);
let status = current_child.wait();
status = current_child.wait();
if status.success() {

Check failure on line 350 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

this if-then-else expression returns a bool literal
true
} else if let Some(code) = status.code() {
log::error!("command failed: {:?}", code);
false
} else {
false
}
}
});
if status.success() {
log::info!("Command succeeded.");
} else if let Some(code) = status.code() {
log::error!("Command failed (exit code: {code})");
} else {
log::error!("Command failed.");
}
});
}

Expand Down

0 comments on commit 794ed2e

Please sign in to comment.