From 40284df8802794709c9d38ce4f3fa8fefe13441f Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Tue, 25 Aug 2026 17:39:03 +0330 Subject: [PATCH] Surface the real build error when website deploy.sh fails. Super Admin was only showing "exited with code 1" because the ERR trap never copied the last compiler or module-not-found line from the deploy log. Co-authored-by: Cursor --- scripts/websites-agent/deploy.sh | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/websites-agent/deploy.sh b/scripts/websites-agent/deploy.sh index 95ff58f..6d71dc9 100755 --- a/scripts/websites-agent/deploy.sh +++ b/scripts/websites-agent/deploy.sh @@ -28,12 +28,45 @@ write_status() { >"$STATUS" } +fail_snippet() { + if [[ ! -f "$LOG" ]]; then + return 0 + fi + local chunk snippet="" + # Only the current deploy (log is appended across runs). + chunk="$(awk 'BEGIN{s=""} /^==== / && /deploy start:/{s=""} {s=s $0 ORS} END{printf "%s", s}' "$LOG")" + snippet="$( + { printf '%s' "$chunk" | grep -E "Error:|Type error|Module not found|ELIFECYCLE|npm ERR!" || true; } \ + | sed 's/\x1b\[[0-9;]*m//g' \ + | tail -n 4 \ + | tr '\n' ' ' \ + | sed 's/[[:space:]]\+/ /g' + )" + if [[ -z "${snippet// }" ]]; then + snippet="$( + printf '%s' "$chunk" \ + | tail -n 12 \ + | sed 's/\x1b\[[0-9;]*m//g' \ + | tr '\n' ' ' \ + | sed 's/[[:space:]]\+/ /g' + )" + fi + printf '%s' "$snippet" +} + echo "==== $(date -u +%Y-%m-%dT%H:%M:%SZ) deploy start: $SLUG ====" write_status "started" "Deploy running" cleanup_fail() { local code=$? - write_status "failed" "deploy.sh exited with code $code" + trap - ERR + local snippet + snippet="$(fail_snippet)" + if [[ -n "${snippet// }" ]]; then + write_status "failed" "exit $code: $snippet" + else + write_status "failed" "deploy.sh exited with code $code" + fi exit "$code" } trap cleanup_fail ERR