This commit is contained in:
CanbiZ 2025-03-14 14:14:26 +01:00
parent 8513b8c032
commit 912cda33e1
2 changed files with 69 additions and 28 deletions

View File

@ -43,6 +43,57 @@ EOF
-d "$JSON_PAYLOAD") || true -d "$JSON_PAYLOAD") || true
} }
get_error_description() {
local exit_code="$1"
case "$exit_code" in
1) echo "General error: An unspecified error occurred." ;;
2) echo "Incorrect shell usage or invalid command arguments." ;;
3) echo "Unexecuted function or invalid shell condition." ;;
4) echo "Error opening a file or invalid path." ;;
5) echo "I/O error: An input/output failure occurred." ;;
6) echo "No such device or address." ;;
7) echo "Insufficient memory or resource exhaustion." ;;
8) echo "Non-executable file or invalid file format." ;;
9) echo "Failed child process execution." ;;
18) echo "Connection to a remote server failed." ;;
22) echo "Invalid argument or faulty network connection." ;;
28) echo "No space left on device." ;;
35) echo "Timeout while establishing a connection." ;;
56) echo "Faulty TLS connection." ;;
60) echo "SSL certificate error." ;;
100) echo "LXC install error: Unexpected error in create_lxc.sh." ;;
101) echo "LXC install error: No network connection detected." ;;
200) echo "LXC creation failed." ;;
201) echo "LXC error: Invalid Storage class." ;;
202) echo "User aborted menu in create_lxc.sh." ;;
203) echo "CTID not set in create_lxc.sh." ;;
204) echo "PCT_OSTYPE not set in create_lxc.sh." ;;
205) echo "CTID cannot be less than 100 in create_lxc.sh." ;;
206) echo "CTID already in use in create_lxc.sh." ;;
207) echo "Template not found in create_lxc.sh." ;;
208) echo "Error downloading template in create_lxc.sh." ;;
209) echo "Container creation failed, but template is intact in create_lxc.sh." ;;
125) echo "Docker error: Container could not start." ;;
126) echo "Command not executable: Incorrect permissions or missing dependencies." ;;
127) echo "Command not found: Incorrect path or missing dependency." ;;
128) echo "Invalid exit signal, e.g., incorrect Git command." ;;
129) echo "Signal 1 (SIGHUP): Process terminated due to hangup." ;;
130) echo "Signal 2 (SIGINT): Manual termination via Ctrl+C." ;;
132) echo "Signal 4 (SIGILL): Illegal machine instruction." ;;
133) echo "Signal 5 (SIGTRAP): Debugging error or invalid breakpoint signal." ;;
134) echo "Signal 6 (SIGABRT): Program aborted itself." ;;
135) echo "Signal 7 (SIGBUS): Memory error, invalid memory address." ;;
137) echo "Signal 9 (SIGKILL): Process forcibly terminated (OOM-killer or 'kill -9')." ;;
139) echo "Signal 11 (SIGSEGV): Segmentation fault, possibly due to invalid pointer access." ;;
141) echo "Signal 13 (SIGPIPE): Pipe closed unexpectedly." ;;
143) echo "Signal 15 (SIGTERM): Process terminated normally." ;;
152) echo "Signal 24 (SIGXCPU): CPU time limit exceeded." ;;
255) echo "Unknown critical error, often due to missing permissions or broken scripts." ;;
*) echo "Unknown error code ($exit_code)." ;;
esac
}
post_to_api_vm() { post_to_api_vm() {
if [[ ! -f /usr/local/community-scripts/diagnostics ]]; then if [[ ! -f /usr/local/community-scripts/diagnostics ]]; then
@ -91,8 +142,8 @@ EOF
} }
POST_UPDATE_DONE=false POST_UPDATE_DONE=false
post_update_to_api() {
post_update_to_api() {
if ! command -v curl &> /dev/null; then if ! command -v curl &> /dev/null; then
return return
fi fi
@ -100,14 +151,18 @@ post_update_to_api() {
if [ "$POST_UPDATE_DONE" = true ]; then if [ "$POST_UPDATE_DONE" = true ]; then
return 0 return 0
fi fi
local API_URL="http://api.community-scripts.org/dev/upload/updatestatus"
local status="${1:-failed}" local status="${1:-failed}"
local error="${2:-No error message}" local exit_code="${2:-0}"
local error_description="$(get_error_description "$exit_code")"
local API_URL="http://api.community-scripts.org/dev/upload/updatestatus"
JSON_PAYLOAD=$(cat <<EOF JSON_PAYLOAD=$(cat <<EOF
{ {
"status": "$status", "status": "$status",
"error": "$error", "error_code": "$exit_code",
"error_message": "$error_description",
"random_id": "$RANDOM_UUID" "random_id": "$RANDOM_UUID"
} }
EOF EOF

View File

@ -78,8 +78,9 @@ error_handler() {
local exit_code="$?" local exit_code="$?"
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" local error_description="$(get_error_description "$exit_code")"
post_update_to_api "failed" "${command}" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL} (${YW}$error_description${CL}): while executing command ${YW}$command${CL}"
post_update_to_api "failed" "$exit_code" "$error_description"
echo -e "\n$error_message\n" echo -e "\n$error_message\n"
} }
@ -1270,26 +1271,11 @@ silent() {
} }
exit_script() { exit_script() {
exit_code=$? # Capture the exit status of the last executed command exit_code=$? # Capture exit status
#200 exit codes indicate error in create_lxc.sh
#100 exit codes indicate error in install.func
if [ $exit_code -ne 0 ]; then if [ $exit_code -ne 0 ]; then
case $exit_code in local error_description="$(get_error_description "$exit_code")"
100) post_update_to_api "failed" "100: Unexpected error in create_lxc.sh" ;; post_update_to_api "failed" "$exit_code" "$error_description"
101) post_update_to_api "failed" "101: No network connection detected in create_lxc.sh" ;;
200) post_update_to_api "failed" "200: LXC creation failed in create_lxc.sh" ;;
201) post_update_to_api "failed" "201: Invalid Storage class in create_lxc.sh" ;;
202) post_update_to_api "failed" "202: User aborted menu in create_lxc.sh" ;;
203) post_update_to_api "failed" "203: CTID not set in create_lxc.sh" ;;
204) post_update_to_api "failed" "204: PCT_OSTYPE not set in create_lxc.sh" ;;
205) post_update_to_api "failed" "205: CTID cannot be less than 100 in create_lxc.sh" ;;
206) post_update_to_api "failed" "206: CTID already in use in create_lxc.sh" ;;
207) post_update_to_api "failed" "207: Template not found in create_lxc.sh" ;;
208) post_update_to_api "failed" "208: Error downloading template in create_lxc.sh" ;;
209) post_update_to_api "failed" "209: Container creation failed, but template is intact in create_lxc.sh" ;;
*) post_update_to_api "failed" "Unknown error, exit code: $exit_code in create_lxc.sh" ;;
esac
fi fi
} }