mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2025-06-19 12:04:20 -04:00
fix-up & enhance advanced error handling
new (internal used) functions: - _exit - _exit_report - _exit_sigint these are used to fix several (wrong) error handlings. new environment variable: - UNATTENDED_PATCHING by default we assume unattended patching, i.e. if an error occurs during the patch, reset or any other process we will report the error and auto close the shell. this is needed as we source functions and code and so cannot simply terminate a master process. instead the whole shell will be terminated so if an error occurs nothing else will be executed (and you should notice easily that something is wrong). without that a (serious) error can still continue the rest of a function and you likely not even noticing the error itself. you can use: export UNATTENDED_PATCHING=0 before or after sourcing init.sh and it will *NOT* auto-close the shell. that way you can check the output and fix any issues. Signed-off-by: steadfasterX <steadfasterX@gmail.com>
This commit is contained in:
parent
fcec1c8887
commit
30859d2c08
2 changed files with 67 additions and 8 deletions
|
@ -21,11 +21,22 @@ _fetchError(){
|
|||
local error_line_number="$2";
|
||||
local last_func="$3";
|
||||
local file=$(echo "$4" | sed "s#$DOS_WORKSPACE_ROOT#\$DOS_WORKSPACE_ROOT#g");
|
||||
|
||||
# ignore when pressing TAB or sim.
|
||||
if [[ "$file" =~ .*bash_completion ]];then return; fi
|
||||
case $last_func in
|
||||
command_not_found_handle|_filedir) return;;
|
||||
esac
|
||||
|
||||
if [ ! -z "$last_func" ] && [ ! -z "$file" ];then
|
||||
echo -e "\e[0;31mERROR: $file -> ${last_func}() ended with status >${last_status}< at line >$((error_line_number -1))<\e[0m";
|
||||
elif [ ! -z "$last_func" ];then
|
||||
echo -e "\e[0;31mERROR: ${last_func}() ended with status >${last_status}< at line >$((error_line_number -1))<\e[0m";
|
||||
else
|
||||
echo -e "\e[0;31mERROR: last command ended with status >${last_status}< at line >$((error_line_number -1))<\e[0m";
|
||||
fi
|
||||
export TR_ERR=$last_status
|
||||
_exit_report
|
||||
}
|
||||
export -f _fetchError;
|
||||
|
||||
|
@ -74,7 +85,7 @@ enterAndClear() {
|
|||
export -f enterAndClear;
|
||||
|
||||
gitReset() {
|
||||
git add -A && git reset --hard;
|
||||
(git add -A && git reset --hard) || true;
|
||||
}
|
||||
export -f gitReset;
|
||||
|
||||
|
@ -88,16 +99,22 @@ applyPatchReal() {
|
|||
git format-patch -1 HEAD --zero-commit --no-signature --output="$currentWorkingPatch";
|
||||
fi;
|
||||
fi;
|
||||
else
|
||||
echo "Applying (git am): $currentWorkingPatch - FAILED"
|
||||
git am --abort || true
|
||||
echo "Applying (patch fallback): $currentWorkingPatch"
|
||||
patch -r - --no-backup-if-mismatch --forward --ignore-whitespace --verbose -p1 < $currentWorkingPatch
|
||||
fi;
|
||||
else
|
||||
git apply "$@";
|
||||
echo "Applying (as diff): $currentWorkingPatch";
|
||||
git apply "$@";
|
||||
fi;
|
||||
}
|
||||
export -f applyPatchReal;
|
||||
|
||||
applyPatch() {
|
||||
currentWorkingPatch=$1;
|
||||
set -E
|
||||
if [ -f "$currentWorkingPatch" ]; then
|
||||
if git apply --check "$@" &> /dev/null; then
|
||||
applyPatchReal "$@";
|
||||
|
@ -110,11 +127,13 @@ applyPatch() {
|
|||
echo "Applied (as 3way): $currentWorkingPatch";
|
||||
else
|
||||
echo -e "\e[0;31mERROR: Cannot apply: $currentWorkingPatch\e[0m";
|
||||
false
|
||||
fi;
|
||||
fi;
|
||||
fi;
|
||||
else
|
||||
echo -e "\e[0;31mERROR: Patch doesn't exist: $currentWorkingPatch\e[0m";
|
||||
false
|
||||
fi;
|
||||
}
|
||||
export -f applyPatch;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue