Skip to content

generateCommand exits the process instead of throwing, so callers cannot clean up #1223

Description

@borisno2

Parent

Follow-up from #1157 / #1218, under spec #1125. Lands on the prisma-8 integration branch, not main.

Problem

generateCommand() in packages/cli/src/commands/generate.ts reports every failure by calling process.exit(1) — around 13 call sites. That is fine for opensaas generate, which is the whole process, but it is now wrong for opensaas dev, which calls generateCommand() as one step of a longer-lived loop that owns resources.

process.exit skips finally blocks and never drains pending async work, so a try/finally in the dev loop cannot run its async stop() on this path no matter where the try starts. When generation fails under opensaas dev, the in-process PGlite is never closed cleanly.

#1218 mitigated what is reachable from a synchronous 'exit' listener — it kills the app child and drops the run's state file, which closes the worst hole (an orphaned next dev left running against a dead database). The clean async shutdown still needs the underlying contract to change.

What to build

Make generateCommand() signal failure by throwing rather than by exiting, so callers decide what to do. The opensaas generate command keeps its current observable behaviour — same message, same exit code — by catching at the CLI entry point. opensaas dev then gets its finally back and can await a clean stop().

Expect a contract change for every caller; check packages/cli/src/index.ts and the dev loop, and any test that asserts on the exit.

Acceptance criteria

  • generateCommand() throws on failure; no process.exit inside it
  • opensaas generate on a failing config still prints the same error and exits 1
  • Under opensaas dev, a generation failure runs the loop's async stop() — the Dev database is closed and its state file removed, verified by a test rather than by inspection
  • The synchronous 'exit' safety net added in opensaas dev brings up the Dev database, generates, reconciles and spawns the app #1218 is reconciled with the new path: kept as a backstop or removed as redundant, deliberately either way

Notes

Raised by the implementer of #1218 while addressing review, and deliberately left out of that PR: refactoring 13 exit sites and changing a contract for every caller does not belong in a PR already under review.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions