[PATCH aiaiai 5/7] aiaiai-email-test-patchset: correct hook calling to actually grab error
Jacob Keller
jacob.e.keller at intel.com
Fri Apr 4 15:06:50 PDT 2014
Using set -e can be ugly, because actually grabbing the return code is
not trivial. It turns out that even using an if statement mucks up the
$?, so the best method is to simply disable -e mode (set +e) and then
enable it again after we call the hook. This is a bit ugly but was the
cleanest implementation I could find that worked.
Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
---
email/aiaiai-email-test-patchset | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset
index 037695740ad5..0d6ba6a1c0c5 100755
--- a/email/aiaiai-email-test-patchset
+++ b/email/aiaiai-email-test-patchset
@@ -288,19 +288,27 @@ hookscript="$(readlink -ev -- $cfg_email_hook)"
if [ -f "$hookscript" ] && [ -x "$hookscript" ]; then
# Hook points to an executable file, so we run it
verbose "Executing \"$hookscript\""
- if ! "$hookscript" "$cfgfile" "$mbox" > "$hookoutput"; then
- hookret=$?
- # Error code 127 is an expected output of the hook, and
- # indicates that we should reject this patch. The reply email
- # will be sent to the user, and the hook is expected to have
- # outputted the rejection indication. As a precaution, the
- # rejection email will include a list of projects supported.
- if [ "$hookret" -eq "127" ]; then
- error_hook_rejected_patch < "$hookoutput"
- else
- error_internal_error_occurred
- fi
+ # We have to disable exit-on-failure here, otherwise there is no way to
+ # grab the exit status of the hook. Using an if statement is prone to
+ # error because ! test in the if statement will change the value of $?
+ # accordingly. It's better to just disable failure here, and then grab
+ # the return value, checking only that.
+ set +e
+ "$hookscript" "$cfgfile" "$mbox" > "$hookoutput"
+ hookret=$?
+ set -e
+
+ # Error code 127 is an expected output of the hook, and
+ # indicates that we should reject this patch. The reply email
+ # will be sent to the user, and the hook is expected to have
+ # outputted the rejection indication. As a precaution, the
+ # rejection email will include a list of projects supported.
+ if [ "$hookret" -eq "127" ]; then
+ error_hook_rejected_patch < "$hookoutput"
+ elif [ "$hookret" -ne "0" ]; then
+ verbose "Hook exited with error code \"$hookret\"..."
+ error_internal_error_occurred
fi
fi
--
1.8.3.1
More information about the aiaiai
mailing list