Skip to content
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
6 changes: 4 additions & 2 deletions cronic
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# --duplicate-stderr options, which may be given in any order.
# The options and the treatment of execution traces are documented in function
# `cronic_help`; run `cronic --help`.
# This script runs under bash 3.2, which is /bin/bash on macOS, so it uses a
# feature of a later bash only after checking the version.

# Exit if a command exits with a non-zero status, and treat unset variables
# as an error.
Expand Down Expand Up @@ -200,8 +202,8 @@ cronic_pattern=$(cronic_trace_pattern)
if [ -n "$cronic_pattern" ] && grep -q "$cronic_pattern" "$cronic_trace"; then
# `|| true` because `grep -v` exits with status 1 when it selects no lines,
# which happens whenever stderr consists only of trace lines. Without it,
# `set -e` would abort the script here, before it produces its report,
# exits with the wrapped command's status, and removes its temporary files.
# `set -e` would abort the script here, before it produces its report, and
# it would exit with status 1 rather than with the wrapped command's status.
grep -v "$cronic_pattern" "$cronic_trace" > "$cronic_err" || true
else
cronic_err=$cronic_trace
Expand Down
7 changes: 4 additions & 3 deletions tests/cronic-test/cronic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#
# `cronic` filters trace lines out of stderr with `grep -v`, which exits with
# status 1 when it selects no lines. `cronic` runs under `set -e`, so an
# unguarded `grep -v` aborted the script at that point: no report was printed,
# the exit status was grep's 1 rather than the wrapped command's, and all of
# the temporary files under /tmp were left behind.
# unguarded `grep -v` would abort the script at that point: no report would be
# printed, and the exit status would be grep's 1 rather than the wrapped
# command's. (The temporary files would still be removed, by `cronic`'s EXIT
# trap, so the left-behind-files check in `check` does not detect that bug.)

set -eu

Expand Down
Loading