Skip to content

fix: propagate server errors to Sentry error handler#245

Open
jakebromberg wants to merge 5 commits intomainfrom
bugfix/sentry-dsn
Open

fix: propagate server errors to Sentry error handler#245
jakebromberg wants to merge 5 commits intomainfrom
bugfix/sentry-dsn

Conversation

@jakebromberg
Copy link
Member

@jakebromberg jakebromberg commented Mar 21, 2026

Summary

  • Three catch blocks were swallowing server errors by sending responses directly, bypassing Sentry.setupExpressErrorHandler(). Changed them to call next(error) so errors reach the Sentry middleware.
  • Fixed dotenv load ordering in both instrument.ts files so SENTRY_DSN is available when Sentry.init() runs during local dev.
  • Added Sentry.captureException() to 8 fire-and-forget catch blocks that only logged to console.error and were invisible to Sentry. Each call includes tags.subsystem for filtering and extra context for debugging.
  • Added test coverage for all error propagation and capture paths, plus full requireAnonymousAuth middleware test suite.
  • Documented SENTRY_DSN and SENTRY_RELEASE in .env.example and CLAUDE.md.

Closes #244
Closes #247

Test plan

  • All 332 unit tests pass (15 new)
  • Typecheck passes across all workspaces
  • Build succeeds for backend and auth
  • Lint passes (0 errors)
  • After deploy, verify errors appear in Sentry dashboard

Jake Bromberg added 4 commits March 20, 2026 19:20
Three catch blocks were sending HTTP responses directly without calling
next(error), preventing errors from reaching Sentry's Express error
handler middleware. This also fixes the dotenv load ordering in
instrument.ts so SENTRY_DSN is available when Sentry.init() runs during
local development.

Error propagation fixes:
- requestLine.controller.ts: parseMessage catch calls next(e)
- checkShowMember.ts: catch calls next(e) instead of res.status(500)
- anonymousAuth.ts: catch calls next(error) instead of res.status(401)

Dotenv ordering fixes:
- Both instrument.ts files load dotenv before Sentry.init()
- Removed redundant dotenv import from auth app.ts
- Added dotenv dependency to backend package.json

Test coverage:
- New: requestLine.parseMessage.test.ts (3 tests)
- New: anonymousAuth.test.ts (5 tests)
- Updated: checkShowMember.test.ts to assert next(error) propagation

Documentation:
- Added SENTRY_DSN and SENTRY_RELEASE to .env.example and CLAUDE.md
- Add moduleNameMapper for @wxyc/authentication in jest.unit.config.ts
  so the workspace package resolves in CI without a build step
- Create tests/mocks/authentication.mock.ts as the default mock
- Fix Prettier formatting in requestLine.parseMessage.test.ts
Errors caught in fire-and-forget callbacks (.catch(), async IIFEs inside res.once('finish'), startup code) were only logged to console.error and never reached Sentry. This adds Sentry.captureException() at 8 catch sites with subsystem tags for filtering:

- flowsheet.controller.ts: metadata fetch failures (subsystem: metadata)
- mirror.middleware.ts: SQL and HTTP mirror sync failures (subsystem: legacy-mirror)
- anonymousAuth.ts: activity recording failures (subsystem: activity-tracking)
- anonymousDevice.service.ts: device activity recording failures (subsystem: activity-tracking)
- auth/app.ts: syncAdminRoles startup failure (subsystem: admin-sync, level: warning)
- requestLine.enhanced.service.ts: Slack posting failure (subsystem: slack, level: warning)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Sentry.captureException() to fire-and-forget catch blocks fix: Server errors not reaching Sentry error handler

1 participant