feat: Improve error handling (#1936)

This commit is contained in:
Kroese
2026-07-21 21:53:21 +02:00
committed by GitHub
parent 958d25d095
commit 48150e7060
3 changed files with 37 additions and 10 deletions
+23 -7
View File
@@ -431,7 +431,7 @@ extractESD() {
local version="$3" local version="$3"
local desc="$4" local desc="$4"
local msg ret index local msg ret index size
local minSize freeSpace bootPad local minSize freeSpace bootPad
local info count totals links local info count totals links
local bootTotal bootLinks bootSize local bootTotal bootLinks bootSize
@@ -448,12 +448,20 @@ extractESD() {
msg="Extracting $desc bootdisk" msg="Extracting $desc bootdisk"
info "$msg..." && html "$msg..." info "$msg..." && html "$msg..."
if [ "$(stat -c%s "$iso")" -lt "$minSize" ]; then if ! size=$(stat -c%s -- "$iso"); then
error "Invalid ESD file: Size is smaller than 100 MB" error "Failed to determine size of ISO file \"$iso\" !"
return 1 return 1
fi fi
rm -rf "$dir" if (( size < minSize )); then
error "The downloaded ISO file is too small!"
return 1
fi
if ! rm -rf -- "$dir"; then
error "Failed to remove directory \"$dir\" !"
return 1
fi
if ! makeDir "$dir"; then if ! makeDir "$dir"; then
error "Failed to create directory \"$dir\" !" error "Failed to create directory \"$dir\" !"
@@ -613,10 +621,14 @@ extractImage() {
local msg="Extracting $desc image" local msg="Extracting $desc image"
info "$msg..." && html "$msg..." info "$msg..." && html "$msg..."
rm -rf "$dir" if ! rm -rf -- "$dir"; then
error "Failed to remove directory \"$dir\" !"
return 1
fi
if ! makeDir "$dir"; then if ! makeDir "$dir"; then
error "Failed to create directory \"$dir\" !" && return 1 error "Failed to create directory \"$dir\" !"
return 1
fi fi
size=$(stat -c%s "$iso") size=$(stat -c%s "$iso")
@@ -627,7 +639,11 @@ extractImage() {
checkFreeSpace "$dir" "$size" || return 1 checkFreeSpace "$dir" "$size" || return 1
rm -rf "$dir" if ! rm -rf -- "$dir"; then
error "Failed to remove directory \"$dir\" !"
return 1
fi
/run/progress.sh "$dir" "$size" "$msg ([P])..." & /run/progress.sh "$dir" "$size" "$msg ([P])..." &
if ! 7z x "$iso" -o"$dir" > /dev/null; then if ! 7z x "$iso" -o"$dir" > /dev/null; then
+7 -2
View File
@@ -883,7 +883,10 @@ fallbackEnglish() {
# still locate the same image, but use English installation media. # still locate the same image, but use English installation media.
LANGUAGE="en" LANGUAGE="en"
rm -f "$iso" if ! rm -f -- "$iso"; then
error "Failed to remove ISO file \"$iso\" !"
return 1
fi
downloadImage "$iso" "$version" "$LANGUAGE" downloadImage "$iso" "$version" "$LANGUAGE"
} }
@@ -1010,7 +1013,9 @@ downloadImage() {
done done
if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then
fallbackEnglish "$iso" "$version" "$lang" "$desc" && return 0 if fallbackEnglish "$iso" "$version" "$lang" "$desc"; then
return 0
fi
fi fi
return 1 return 1
+7 -1
View File
@@ -34,7 +34,13 @@ boot() {
if [ -s "$QEMU_PTY" ]; then if [ -s "$QEMU_PTY" ]; then
if [ "$(stat -c%s "$QEMU_PTY")" -gt 7 ]; then if [ "$(stat -c%s "$QEMU_PTY")" -gt 7 ]; then
if ! bootFailed; then if ! bootFailed; then
info "$(app) started successfully, visit http://127.0.0.1:8006/ to view the screen..."
if [[ "${DISPLAY,,}" == "web" ]] && ! disabled "${WEB:-Y}"; then
info "$(app) started successfully, visit http://127.0.0.1:$WEB_PORT/ to view the screen..."
else
info "$(app) started successfully."
fi
return 0 return 0
fi fi
fi fi