Revamp debugging

This commit is contained in:
Muhammad Rivan 2021-06-03 07:29:26 +07:00
parent 0a1f248269
commit eb5075aab5
No known key found for this signature in database
GPG key ID: C56A200FD936FAAA
2 changed files with 81 additions and 75 deletions

View file

@ -152,8 +152,5 @@ else
fi
echo; prompt -w "${final_msg}"; echo
rootify ls /mama; ls /mama; ls /mama
ls /mama
ls /mama
[[ -x /usr/bin/notify-send ]] && notify-send "'${name}' theme has been installed. Enjoy!" "${notif_msg}" -i "dialog-information-symbolic"
fi

View file

@ -147,7 +147,7 @@ anim=(
)
###############################################################################
# UTILITIES #
# CORE UTILITIES #
###############################################################################
start_animation() {
@ -189,6 +189,84 @@ prompt() {
esac
}
###############################################################################
# SELF SAFETY #
###############################################################################
##### This is the core of error handling, make sure there's no error here #####
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
start_animation; sleep 2; stop_animation; echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
prompt -e "ERROR: Whitesur installer or tweaks is already running. Probably it's run by '$(ls -ld "${WHITESUR_TMP_DIR}" | awk '{print $3}')'"
exit 1
fi
fi
rm -rf "${WHITESUR_TMP_DIR}"
mkdir -p "${WHITESUR_TMP_DIR}"; exec 2> "${WHITESUR_TMP_DIR}/error_log.txt"
signal_exit() {
rm -rf "${WHITESUR_TMP_DIR}"
stop_animation
}
operation_aborted() {
IFS=$'\n'
local sources=($(basename -a "${WHITESUR_SOURCE[@]}" "${BASH_SOURCE[@]}" | sort -u))
local dist_ids=($(awk -F '=' '/ID/{print $2}' "/etc/os-release"))
local repo_ver=""
local lines=()
if ! repo_ver="$(cd "${REPO_DIR}"; git log -1 --date=format-local:"%FT%T%z" --format="%ad")"; then
if ! repo_ver="$(date -r "${REPO_DIR}" +"%FT%T%z")"; then
repo_ver="unknown"
fi
fi
clear
prompt -e "\n\n Oops! Operation has been aborted or failed...\n"
prompt -e "=========== ERROR LOG ==========="
if ! awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt"; then
prompt -e ">>>>>>> No error log found <<<<<<"
fi
prompt -e "\n =========== ERROR INFO =========="
prompt -e "FOUND :"
for i in "${sources[@]}"; do
lines=($(grep -Fn "${error_snippet:-${BASH_COMMAND}}" "${REPO_DIR}/${i}" | cut -d : -f 1 || echo ""))
prompt -e " >>> ${i}$(IFS=';'; [[ "${lines[*]}" ]] && echo " at ${lines[*]}")"
done
prompt -e "SNIPPET:\n >>> ${error_snippet:-${BASH_COMMAND}}"
prompt -e "TRACE :"
for i in "${FUNCNAME[@]}"; do
prompt -e " >>> ${i}"
done
prompt -e "\n =========== SYSTEM INFO ========="
prompt -e "DISTRO : $(IFS=';'; echo "${dist_ids[*]}")"
prompt -e "SUDO : $([[ -w "/" ]] && echo "yes" || echo "no")"
prompt -e "GNOME : ${GNOME_VERSION}"
prompt -e "REPO : ${repo_ver}\n"
prompt -i "TIP: you can google or report to us the infos above\n"
prompt -i "https://github.com/vinceliuice/WhiteSur-gtk-theme/issues\n\n"
rm -rf "${WHITESUR_TMP_DIR}"; exit 1
}
trap 'operation_aborted' ERR
trap 'signal_exit' INT EXIT TERM
###############################################################################
# USER UTILITIES #
###############################################################################
helpify_title() {
printf "${c_cyan}%s${c_blue}%s ${c_green}%s\n\n" "Usage: " "$0" "[OPTIONS...]"
printf "${c_cyan}%s\n" "OPTIONS:"
@ -513,60 +591,6 @@ userify() {
trap signal_exit SIGINT
}
signal_exit() {
rm -rf "${WHITESUR_TMP_DIR}"
stop_animation
}
operation_aborted() {
IFS=$'\n'
local sources=($(basename -a "${WHITESUR_SOURCE[@]}" "${BASH_SOURCE[@]}" | sort -u))
local dist_ids=($(awk -F '=' '/ID/{print $2}' "/etc/os-release"))
local repo_ver=""
local lines=()
if ! repo_ver="$(cd "${REPO_DIR}"; git log -1 --date=format-local:"%FT%T%z" --format="%ad")"; then
if ! repo_ver="$(date -r "${REPO_DIR}" +"%FT%T%z")"; then
repo_ver="unknown"
fi
fi
clear
prompt -e "\n\n Oops! Operation has been aborted or failed...\n"
prompt -e "=========== ERROR LOG ==========="
if [[ -f "${WHITESUR_TMP_DIR}/error_log.txt" ]]; then
awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt"
fi
prompt -e "\n =========== ERROR INFO =========="
prompt -e "FOUND :"
for i in "${sources[@]}"; do
lines=($(grep -Fn "${error_snippet:-${BASH_COMMAND}}" "${REPO_DIR}/${i}" | cut -d : -f 1 || echo ""))
prompt -e " >>> ${i} $(IFS=';'; [[ "${lines[*]}" ]] && echo "at ${lines[*]}")"
done
prompt -e "SNIPPET:\n >>> ${error_snippet:-${BASH_COMMAND}}"
prompt -e "TRACE :"
for i in "${FUNCNAME[@]}"; do
prompt -e " >>> ${i}"
done
prompt -e "\n =========== SYSTEM INFO ========="
prompt -e "DISTRO : $(IFS=';'; echo "${dist_ids[*]}")"
prompt -e "SUDO : $([[ -w "/" ]] && echo "yes" || echo "no")"
prompt -e "GNOME : ${GNOME_VERSION}"
prompt -e "REPO : ${repo_ver}\n"
prompt -i "TIP: you can google or report to us the infos above\n"
prompt -i "https://github.com/vinceliuice/WhiteSur-gtk-theme/issues\n\n"
rm -rf "${WHITESUR_TMP_DIR}"; exit 1
}
usage() {
prompt -e "Usage function is not implemented"; exit 1
}
@ -577,22 +601,7 @@ finalize_argument_parsing() {
[[ "${has_any_error}" == "true" ]] && exit 1 || exit 0
elif [[ "${has_any_error}" == "true" ]]; then
echo; prompt -i "Try '$0 --help' for more information."; exit 1
else
[[ "${need_dialog[@]}" =~ "true" ]] && echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
start_animation; sleep 2; stop_animation; echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
prompt -e "ERROR: Whitesur installer or tweaks is already running. Probably it's run by '$(ls -ld "${WHITESUR_TMP_DIR}" | awk '{print $3}')'"
exit 1
fi
fi
rm -rf "${WHITESUR_TMP_DIR}"; mkdir -p "${WHITESUR_TMP_DIR}"
rm -rf "${THEME_SRC_DIR}/sass/_theme-options-temp.scss"
exec 2> "${WHITESUR_TMP_DIR}/error_log.txt"
trap 'operation_aborted' ERR
trap 'signal_exit' INT EXIT TERM
elif [[ "${need_dialog[@]}" =~ "true" ]]; then
echo
fi
}