From 4fa13a1d28e2d1b18916997727e453991e79972e Mon Sep 17 00:00:00 2001 From: Jackson Roberts Date: Wed, 8 Apr 2026 14:31:22 +0000 Subject: [PATCH] fix(migrate): fix set -e swallowing prisma output on failure POSIX sh exits a script on the assignment line when command substitution exits non-zero under set -e -- before the subsequent echo ever runs. DEPLOY_OUTPUT=$(cmd 2>&1) # <- script exits here if cmd fails EXIT_CODE=$? echo "$DEPLOY_OUTPUT" # <- never reached Fix: use the || idiom, which puts the LHS in a compound-command context where set -e does not apply, and still captures the real exit code: EXIT_CODE=0 DEPLOY_OUTPUT=$(cmd 2>&1) || EXIT_CODE=$? echo "$DEPLOY_OUTPUT" # <- always runs Applied the same fix to the resolve call. --- api/prisma/migrate-entrypoint.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/prisma/migrate-entrypoint.sh b/api/prisma/migrate-entrypoint.sh index 7eacdcb..40b2161 100755 --- a/api/prisma/migrate-entrypoint.sh +++ b/api/prisma/migrate-entrypoint.sh @@ -14,8 +14,8 @@ while [ $ATTEMPT -lt $MAX_RETRIES ]; do ATTEMPT=$((ATTEMPT + 1)) echo "[migrate] Running prisma migrate deploy (attempt $ATTEMPT)..." - DEPLOY_OUTPUT=$(bunx prisma migrate deploy 2>&1) - EXIT_CODE=$? + EXIT_CODE=0 + DEPLOY_OUTPUT=$(bunx prisma migrate deploy 2>&1) || EXIT_CODE=$? echo "$DEPLOY_OUTPUT" if [ $EXIT_CODE -eq 0 ]; then @@ -30,7 +30,14 @@ while [ $ATTEMPT -lt $MAX_RETRIES ]; do FAILED=$(echo "$DEPLOY_OUTPUT" | grep -oE '\`[0-9]{14}(_[a-zA-Z_]+)?\`' | tr -d '\`' | head -1) if [ -n "$FAILED" ]; then echo "[migrate] Resolving failed migration as rolled-back: $FAILED" - bunx prisma migrate resolve --rolled-back "$FAILED" + RESOLVE_OUTPUT="" + RESOLVE_EXIT=0 + RESOLVE_OUTPUT=$(bunx prisma migrate resolve --rolled-back "$FAILED" 2>&1) || RESOLVE_EXIT=$? + echo "$RESOLVE_OUTPUT" + if [ $RESOLVE_EXIT -ne 0 ]; then + echo "[migrate] Failed to resolve migration $FAILED (exit $RESOLVE_EXIT). Aborting." + exit 1 + fi continue fi fi