From 48150e706000f609460b9b5b32832a256289ee1a Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 21 Jul 2026 21:53:21 +0200 Subject: [PATCH] feat: Improve error handling (#1936) --- src/install.sh | 30 +++++++++++++++++++++++------- src/mido.sh | 9 +++++++-- src/power.sh | 8 +++++++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/install.sh b/src/install.sh index 0bc0daed..96f0a993 100644 --- a/src/install.sh +++ b/src/install.sh @@ -431,7 +431,7 @@ extractESD() { local version="$3" local desc="$4" - local msg ret index + local msg ret index size local minSize freeSpace bootPad local info count totals links local bootTotal bootLinks bootSize @@ -448,12 +448,20 @@ extractESD() { msg="Extracting $desc bootdisk" info "$msg..." && html "$msg..." - if [ "$(stat -c%s "$iso")" -lt "$minSize" ]; then - error "Invalid ESD file: Size is smaller than 100 MB" + if ! size=$(stat -c%s -- "$iso"); then + error "Failed to determine size of ISO file \"$iso\" !" return 1 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 error "Failed to create directory \"$dir\" !" @@ -613,10 +621,14 @@ extractImage() { local msg="Extracting $desc image" 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 - error "Failed to create directory \"$dir\" !" && return 1 + error "Failed to create directory \"$dir\" !" + return 1 fi size=$(stat -c%s "$iso") @@ -627,7 +639,11 @@ extractImage() { 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])..." & if ! 7z x "$iso" -o"$dir" > /dev/null; then diff --git a/src/mido.sh b/src/mido.sh index 225ca5b1..b700e311 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -883,7 +883,10 @@ fallbackEnglish() { # still locate the same image, but use English installation media. LANGUAGE="en" - rm -f "$iso" + if ! rm -f -- "$iso"; then + error "Failed to remove ISO file \"$iso\" !" + return 1 + fi downloadImage "$iso" "$version" "$LANGUAGE" } @@ -1010,7 +1013,9 @@ downloadImage() { done if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then - fallbackEnglish "$iso" "$version" "$lang" "$desc" && return 0 + if fallbackEnglish "$iso" "$version" "$lang" "$desc"; then + return 0 + fi fi return 1 diff --git a/src/power.sh b/src/power.sh index d3b56cd7..36a2919d 100644 --- a/src/power.sh +++ b/src/power.sh @@ -34,7 +34,13 @@ boot() { if [ -s "$QEMU_PTY" ]; then if [ "$(stat -c%s "$QEMU_PTY")" -gt 7 ]; 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 fi fi