Skip to content

Commit 3ace981

Browse files
committed
Ensure errors are always shown, regardless of log level
1 parent afbfc31 commit 3ace981

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

watcherd

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ IFS=$'\n'
2525

2626
# Versioning
2727
MY_NAME="watcherd"
28-
MY_DATE="2020-12-11"
28+
MY_DATE="2022-12-17"
2929
MY_URL="https://github.com/devilbox/watcherd"
3030
MY_AUTHOR="cytopia <[email protected]>"
3131
MY_GPGKEY="0xA02C56F0"
32-
MY_VERSION="1.0.2"
32+
MY_VERSION="1.0.3"
3333
MY_LICENSE="MIT"
3434

3535
# Default settings
@@ -130,14 +130,16 @@ function action() {
130130
action="${action//%p/${directory}}"
131131
action="${action//%n/${name}}"
132132

133-
if eval "${action}"; then
133+
if OUTPUT="$( eval "${action}" 2>&1 )"; then
134134
if [ "${verbose}" -gt "0" ]; then
135135
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
136136
fi
137137
return 0
138138
else
139-
if [ "${verbose}" -gt "0" ]; then
140-
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
139+
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}" >&2
140+
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${action}" >&2
141+
if [ -n "${OUTPUT}" ]; then
142+
printf "%s: [%s] [ERR] %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${OUTPUT}" >&2
141143
fi
142144
return 1
143145
fi
@@ -151,14 +153,15 @@ function trigger() {
151153
# Only run trigger when command has been specified (not empty)
152154
if [ -n "${action}" ]; then
153155
if [ "${changes}" -eq "1" ]; then
154-
if eval "${action}"; then
156+
if OUTPUT="$( eval "${action}" 2>&1 )"; then
155157
if [ "${verbose}" -gt "0" ]; then
156158
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
157159
fi
158160
return 0
159161
else
160-
if [ "${verbose}" -gt "0" ]; then
161-
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
162+
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}" >&2
163+
if [ -n "${OUTPUT}" ]; then
164+
printf "%s: [%s] [ERR] %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${OUTPUT}" >&2
162165
fi
163166
# Also return 0 here in order to not abort the loop
164167
return 0

0 commit comments

Comments
 (0)