ReviewOS

stacks/bun-query-builder

Library installs a process-wide unhandledRejection handler that silently swallows DB errors

#1040
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

Importing db.ts installs a process-level unhandledRejection listener that suppresses any rejection whose message contains "database"/"does not exist" or code 3D000/ERR_POSTGRES_SERVER_ERROR. The comment says "during tests," but this runs in every consumer's process and will mask genuine production rejections (e.g. a real "relation does not exist" bug). A library installing a silent global rejection handler is a strong smell.

Location

src/db.ts:~540-558.

Suggested fix

Scope this to test setup only (a test preload), or at minimum log under config.verbose instead of fully suppressing.

Severity: medium. Found via internal code audit.

10 days ago

Fixed in 83854a3. Removed the process-wide unhandledRejection handler from db.ts. It was worse than 'swallows DB errors': any unhandledRejection listener suppresses the runtime's default crash for every rejection, and this one's body matched only DB connection errors while silently dropping the rest — masking genuine production bugs in every consumer process. The expected test-time 'database does not exist' rejections are surfaced/awaited at query time now (#1022); the full suite passes without it. Full suite green.

Sign in to comment on this issue.