From 26874c36035e7b0323012347b7afdbfe3ab96b92 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Wed, 6 May 2026 11:26:42 +0200 Subject: [PATCH] Nest command unhandled error process exit 1 (#20312) # Introduction When running the `run-instance-commands` on a migration failure the process wouldn't throw at all Leading to conditional flow to keep going whereas it should have stopped This update is very invasive and impacts all the nest commander registered commands We should keep in mind that it impacts the way we create and init database and so on But I think that's for the best, as cli that never exit 1 is counterintuitive --- .../rootfs/etc/s6-overlay/scripts/init-db.sh | 20 ++++++++++--------- packages/twenty-docker/twenty/entrypoint.sh | 14 ++++++++++--- packages/twenty-server/src/command/command.ts | 2 ++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/twenty-docker/twenty-app-dev/rootfs/etc/s6-overlay/scripts/init-db.sh b/packages/twenty-docker/twenty-app-dev/rootfs/etc/s6-overlay/scripts/init-db.sh index 50ad6d2538..39339ed53e 100755 --- a/packages/twenty-docker/twenty-app-dev/rootfs/etc/s6-overlay/scripts/init-db.sh +++ b/packages/twenty-docker/twenty-app-dev/rootfs/etc/s6-overlay/scripts/init-db.sh @@ -34,25 +34,27 @@ has_schema=$(PGPASSWORD=twenty psql -h localhost -U twenty -d default -tAc \ "SELECT EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'core')") if [ "$has_schema" = "f" ]; then - step_start "Running initial database setup" - NODE_OPTIONS="--max-old-space-size=1500" node ./dist/database/scripts/setup-db.js + step_start "Running initial database setup and migrations" + yarn database:init:prod step_done fi -step_start "Running migrations" -yarn database:migrate:prod --force -step_done - step_start "Flushing cache" -yarn command:prod cache:flush +if ! yarn command:prod cache:flush; then + echo "Warning: Failed to flush cache before upgrade, but continuing startup..." +fi step_done step_start "Running upgrade" -yarn command:prod upgrade +if ! yarn command:prod upgrade; then + echo "Warning: Upgrade completed with errors. Some workspaces may not be fully migrated. Check logs for details." +fi step_done step_start "Flushing cache" -yarn command:prod cache:flush +if ! yarn command:prod cache:flush; then + echo "Warning: Failed to flush cache after upgrade, but continuing startup..." +fi step_done # Only seed on first boot — check if the dev workspace already exists diff --git a/packages/twenty-docker/twenty/entrypoint.sh b/packages/twenty-docker/twenty/entrypoint.sh index ff63f2f5f5..fd85657f5d 100755 --- a/packages/twenty-docker/twenty/entrypoint.sh +++ b/packages/twenty-docker/twenty/entrypoint.sh @@ -16,9 +16,17 @@ setup_and_migrate_db() { yarn database:init:prod fi - yarn command:prod cache:flush - yarn command:prod upgrade - yarn command:prod cache:flush + if ! yarn command:prod cache:flush; then + echo "Warning: Failed to flush cache before upgrade, but continuing startup..." + fi + + if ! yarn command:prod upgrade; then + echo "Warning: Upgrade completed with errors. Some workspaces may not be fully migrated. Check logs for details." + fi + + if ! yarn command:prod cache:flush; then + echo "Warning: Failed to flush cache after upgrade, but continuing startup..." + fi echo "Successfully migrated DB!" } diff --git a/packages/twenty-server/src/command/command.ts b/packages/twenty-server/src/command/command.ts index 3a156cc972..7e0e28a267 100644 --- a/packages/twenty-server/src/command/command.ts +++ b/packages/twenty-server/src/command/command.ts @@ -13,6 +13,8 @@ async function bootstrap() { if (shouldCaptureException(err)) { exceptionHandlerService.captureExceptions([err]); } + + process.exitCode = 1; }; const app = await CommandFactory.createWithoutRunning(CommandModule, {