fix: propagate server errors to Sentry error handler#245
Open
jakebromberg wants to merge 5 commits intomainfrom
Open
fix: propagate server errors to Sentry error handler#245jakebromberg wants to merge 5 commits intomainfrom
jakebromberg wants to merge 5 commits intomainfrom
Conversation
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)
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sentry.setupExpressErrorHandler(). Changed them to callnext(error)so errors reach the Sentry middleware.instrument.tsfiles soSENTRY_DSNis available whenSentry.init()runs during local dev.Sentry.captureException()to 8 fire-and-forget catch blocks that only logged toconsole.errorand were invisible to Sentry. Each call includestags.subsystemfor filtering andextracontext for debugging.requireAnonymousAuthmiddleware test suite.SENTRY_DSNandSENTRY_RELEASEin.env.exampleand CLAUDE.md.Closes #244
Closes #247
Test plan