Skip to content

Startup hooks exit with code 0 on error, breaking systemd/Docker #175

@dmanto

Description

@dmanto

Description:

When onStart() or other startup hooks throw an error, the process exits with code 0 instead of 1. This breaks systemd's Restart=on-failure and container orchestration.

Reproduce:

app.onStart(async () => {
  throw new Error('DB connection failed');
});
app.start();
$ node index.js server
[error] DB connection failed
$ echo $?
0  # Should be 1!

Root cause:

src/app.ts:504 catches all errors but only logs them without exiting.

Fix:

Exit with code 1 when detectImport !== false. This preserves test compatibility and doesn't affect runtime route errors (which correctly return 500 responses without exiting).

I can provide a PR with tests if this approach sounds good.

Tests:

We should add a test/startup-error.js, covering different hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions