Stops check_error function swallowing "errors"
* When a potential error is presented to check_error it does not handle
the "error" prefix but only "ERROR"
* Uses awk to upper-case the error-message to then check for "ERROR"
@@ -68,10 +68,22 @@ readopt() {
done
}
+contains_error() {
+ local msg="${1:-}"
+
+ #
+ # Uppercase the msg to determine if it contains ERROR
+ #
+ if awk 'BEGIN {exit !index(toupper(ARGV[2]), toupper(ARGV[1]))}' "ERROR" "$1"; then
+ echo "YES"
+ else
+ echo "NO"
+ fi
+}
check_error() {
local msg="$*"
- if [ "${msg//ERROR/}" != "${msg}" ]; then
+ if [ "$(contains_error "$msg")" == "YES" ]; then
if [ -n "${ERROR_FILE:-}" ] && [ -f "$ERROR_FILE" ] && ! grep "$msg" $ERROR_FILE; then
local tmp=$(mktemp /tmp/error-XXXX)
echo ${msg} >>$tmp
@@ -90,7 +102,8 @@ check_error() {
print_error() {
local exit_code=$?
local error_file="${1:-}"
- if [ -f $error_file ] && grep -q "ERROR" $error_file; then
+
+ if [ -f $error_file ] && [ "$(contains_error "$(cat $error_file)")" == "YES" ]; then
cat $error_file
elif [ $exit_code -ne 0 ]; then
echo "ERROR: Last command exited with $exit_code"
