Fix error trap with return error to STD ERR
This commit is contained in:
@@ -6,10 +6,10 @@ if [ -z "${MODULE}" ]; then
|
|||||||
fi;
|
fi;
|
||||||
|
|
||||||
set -ETu #-e -o pipefail
|
set -ETu #-e -o pipefail
|
||||||
trap error_trap ERR
|
trap _catch ERR
|
||||||
trap cleanup SIGINT SIGTERM
|
trap _cleanup SIGINT SIGTERM
|
||||||
|
|
||||||
cleanup() {
|
_cleanup() {
|
||||||
# script cleanup here
|
# script cleanup here
|
||||||
echo "Script abort: $? @LINE: $(caller)";
|
echo "Script abort: $? @LINE: $(caller)";
|
||||||
# unset exported vars
|
# unset exported vars
|
||||||
@@ -17,8 +17,8 @@ cleanup() {
|
|||||||
# end trap
|
# end trap
|
||||||
trap - SIGINT SIGTERM
|
trap - SIGINT SIGTERM
|
||||||
}
|
}
|
||||||
error_trap() {
|
_catch() {
|
||||||
echo "Some part of the script failed with an error: $? @COMMAND: '$BASH_COMMAND' @LINE: $(caller)";
|
echo "Some part of the script failed with ERROR: $? @COMMAND: '$BASH_COMMAND' @LINE: $(caller)" >&2;
|
||||||
# exit caller so we do not catch the same error again
|
# exit caller so we do not catch the same error again
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user