fix(switch): detail love-nx fetch failures with retry hint

SWBLD-05: on download failure print URL, curl/wget exit and HTTP status,
and an explicit retry: scripts/build_switch.sh --fetch line. Extend the
offline selftest to cover that path without a live network asset.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Andrew Quenehen
2026-08-01 12:53:06 -03:00
parent 9a467d4bf1
commit 9147a6413e
2 changed files with 69 additions and 10 deletions
+39 -9
View File
@@ -15,7 +15,18 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOVE_NX_TAG="11.5-nx1"
LOVE_NX_DIR="$ROOT/.bazinga/love-nx/$LOVE_NX_TAG"
MANIFEST="$ROOT/scripts/switch/love-nx-11.5-nx1.sha256"
BASE_URL="https://github.com/retronx-team/love-nx/releases/download/${LOVE_NX_TAG}"
# Override for offline selftests (never used in release/docs as the default).
BASE_URL="${GEN1_LOVE_NX_BASE_URL:-https://github.com/retronx-team/love-nx/releases/download/${LOVE_NX_TAG}}"
fail_download() {
local url="$1"
local detail="$2"
rm -f "${3:-}"
fail "download failed: $url
detail: $detail
retry: scripts/build_switch.sh --fetch
See docs/switch-build.md (mode --fetch)."
}
read_manifest_hash() {
local name="$1"
@@ -29,15 +40,35 @@ read_manifest_hash() {
printf '%s' "$hash"
}
# Downloads url → dest. On failure prints structured error (URL, tool status, retry).
download_file() {
local url="$1"
local dest="$2"
local rc=0 http_code errf
if command -v curl >/dev/null 2>&1; then
curl -fL --retry 3 --retry-delay 1 -o "$dest" "$url"
errf="$(mktemp "${TMPDIR:-/tmp}/love-nx-curl.XXXXXX")"
http_code="$(curl -fL --retry 3 --retry-delay 1 -o "$dest" -w '%{http_code}' \
"$url" 2>"$errf")" || rc=$?
if [ "$rc" -ne 0 ]; then
fail_download "$url" \
"curl exit $rc; HTTP status ${http_code:-unknown}; $(tr '\n' ' ' <"$errf" | sed 's/[[:space:]]*$//')" \
"$dest"
fi
rm -f "$errf"
elif command -v wget >/dev/null 2>&1; then
wget -O "$dest" "$url"
errf="$(mktemp "${TMPDIR:-/tmp}/love-nx-wget.XXXXXX")"
wget -O "$dest" "$url" 2>"$errf" || rc=$?
if [ "$rc" -ne 0 ]; then
fail_download "$url" \
"wget exit $rc; $(tr '\n' ' ' <"$errf" | sed 's/[[:space:]]*$//')" \
"$dest"
fi
rm -f "$errf"
else
fail "need curl or wget to download love-nx"
fail "need curl or wget to download love-nx
retry: scripts/build_switch.sh --fetch
See docs/switch-build.md (mode --fetch)."
fi
}
@@ -62,15 +93,14 @@ fetch_one() {
mkdir -p "$LOVE_NX_DIR"
tmp="$(mktemp "${TMPDIR:-/tmp}/love-nx-${name}.XXXXXX")"
say "downloading $name"
if ! download_file "$url" "$tmp"; then
rm -f "$tmp"
fail "download failed: $url"
fi
# download_file fails the script with fail_download (URL + status + retry).
download_file "$url" "$tmp"
actual="$(sha256_file "$tmp")"
if [ "$actual" != "$expected" ]; then
rm -f "$tmp"
fail "$name checksum mismatch (expected $expected, got $actual) — $url"
fail "$name checksum mismatch (expected $expected, got $actual) — $url
retry: scripts/build_switch.sh --fetch"
fi
mv "$tmp" "$dest"
+30 -1
View File
@@ -51,8 +51,10 @@ MISSING=""
printf '%s' "$HELP_LC" | grep -q 'fetch' || MISSING="${MISSING} fetch"
printf '%s' "$HELP_LC" | grep -q 'loose' || MISSING="${MISSING} loose"
printf '%s' "$HELP_LC" | grep -q 'fused' || MISSING="${MISSING} fused"
printf '%s' "$HELP_LC" | grep -Eq 'auto-download|downloads' || MISSING="${MISSING} auto-download"
printf '%s' "$HELP_LC" | grep -Eq 'non-goal|does not|never' || MISSING="${MISSING} non-goals"
if [ -z "$MISSING" ]; then
ok "build_switch.sh --help mentions fetch, loose, fused"
ok "build_switch.sh --help mentions fetch, loose, fused (+ auto-download/non-goals)"
else
bad "build_switch.sh --help missing:$MISSING"
fi
@@ -150,6 +152,33 @@ else
ok "fetch idempotent skipped (no local pin binaries; offline)"
fi
# ---------------------------------------------------------------------------
# 5b2. Mid-fetch / network failure: URL + tool status + retry --fetch (SWBLD-05)
# ---------------------------------------------------------------------------
FETCH_FAIL_ERR="$STAGING/fetch-fail.err"
FETCH_FAIL_OUT="$STAGING/fetch-fail.out"
FETCH_FAIL_RC=0
PIN_MOVED=""
if [ -d "$PIN_DIR" ]; then
PIN_MOVED="$STAGING/pin-backup"
mv "$PIN_DIR" "$PIN_MOVED"
fi
# Closed port / unreachable host — no real network asset required.
GEN1_LOVE_NX_BASE_URL="http://127.0.0.1:1" \
"$ROOT/scripts/switch/fetch_love_nx.sh" >"$FETCH_FAIL_OUT" 2>"$FETCH_FAIL_ERR" || FETCH_FAIL_RC=$?
if [ -n "$PIN_MOVED" ]; then
rm -rf "$PIN_DIR"
mv "$PIN_MOVED" "$PIN_DIR"
fi
if [ "$FETCH_FAIL_RC" -ne 0 ] \
&& grep -q 'download failed:' "$FETCH_FAIL_ERR" \
&& grep -Eq 'curl exit|wget exit|HTTP status' "$FETCH_FAIL_ERR" \
&& grep -q 'retry: scripts/build_switch.sh --fetch' "$FETCH_FAIL_ERR"; then
ok "fetch network failure cites URL status and retry --fetch"
else
bad "fetch failure should cite status + retry --fetch (rc=$FETCH_FAIL_RC err=$(cat "$FETCH_FAIL_ERR"))"
fi
# ---------------------------------------------------------------------------
# 5c. fail_fused_toolchain mentions docs/switch-build.md
# ---------------------------------------------------------------------------