lib.sh: simplify err()

Rely once again on err_, but still explicitly add an exit
just below, in case I made a mistake one day.

err() is essentially a trap that triggers in case I mess
up an error function, so that it doesn't reliably exit.

So, the idea is that everything calls err(), and err() is
almost never modified, or modified very carefully.

If error exits were ever broken, the result could be quite
unpredictable, so lbmk has very strict error handling, and
great care is taken to ensure that it does reliably exit.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2025-05-04 16:23:11 +01:00
parent d4776f065c
commit eacd9808b6
+5 -11
View File
@@ -185,19 +185,13 @@ err()
fi
(
$real_err "$@" || printf \
"WARNING: Err function '%s' *returned* 1. Will exit 1 anyway\n" \
"$real_err" 1>&2
printf "WARNING: Err function '%s' didn't exit. Will exit 1 anyway\n" \
"$real_err" 1>&2
exit 1
$real_err "$@" || err_ "Error function '$real_err' *returned* 1"
err_ "Error function '$real_err' didn't exit"
exit 1 # just in case!
) || xbmk_err_val=1 # otherwise, it wrongly did exit 0, not exit 1
[ $xbmk_err_val -eq 0 ] && printf \
"WARNING: Err function '%s' did exit 0. Will exit 1 anyway.\n" \
"$real_err" 1>&2
exit 1
[ $xbmk_err_val -eq 0 ] && err_ "Error function '$real_err' did exit 0"
exit 1 # just in case!
}
err_()