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 <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-25 17:39:03 +03:30
co-authored by Cursor
parent 20cc0bbd78
commit 40284df880
+34 -1
View File
@@ -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