Repository navigation
fix: print and capture auth handler errors - #454
Merged
Merged
Conversation
Auth landing handlers, OAuth callbacks and auth hooks catch their own errors and return a redirect or a fallback response, so the route handler's captureError never saw them and they reached stdout only. Each call site now prints the error with logError (stdout, so it stays on the Logs page) and sends it to APM with captureError. captureError accepts unknown and wraps non-Error values. Based on the approach in #388. Co-authored-by: vardhman bengani <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
eduard-piliposyan
approved these changes
Nov 9, 2026
eduard-piliposyan
left a comment
Contributor
There was a problem hiding this comment.
Looks good. This fixes #334, and redirects and responses are unchanged. Widening captureError to accept unknown doesn't break existing callers of the public modelence/telemetry export. The auth and telemetry suites pass locally (610/610).
Some notes, none of them blocking:
- Log level now applies.
logErrorchecksMODELENCE_LOG_LEVEL, but the oldconsole.erroralways printed. If telemetry is on and the level is set to something outsidedebug/info/error(saywarn), these errors only go to APM. The route handler already behaves this way, so this is fine. Just calling it out. - Errors print twice locally. With telemetry off,
logErrorprints the message and error, and thencaptureErrorprints the error again. captureErrorcan throw on unusual values.new Error(String(error))throws if the value can't be turned into a string, for exampleObject.create(null). Since it runs insidecatchblocks, infireAuthHookit would hide the real error, and in the landing handlers it would turn the 302 into a 500.handler.tsandmethods/index.tsalready use the same pattern, so this isn't new. Atry { String(error) } catch { 'Unknown error' }would close it if you want.- Not changed by this PR: in
verification.ts,handleVerifyEmailstill logs nothing when the thrown value isn't anError, because of theinstanceofcheck that was already there.
captureError built its message with String(error), which throws for values such as Object.create(null). It runs inside catch blocks, so that second throw hid the original error, or turned an auth landing redirect into a 500. It now falls back to 'Unknown error'. handleVerifyEmail only logged and captured failures that were Error instances. It now does so for every failure; only the onEmailVerificationError hook, which expects an Error, stays behind the instanceof check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #334. Supersedes #388 by @flcrom, whose commit credit is kept via
Co-authored-by.Problem
Auth landing handlers (magic link, password reset, email verification), the GitHub/Google OAuth callbacks, and auth hooks catch their own errors and return a 302 or a fallback response. The route handler's
captureErrornever sees these errors, so they reached stdout only and never APM.#388 switched these sites to
captureErroralone. With telemetry on (deployed apps), that sends to APM and prints nothing, so the errors would have dropped off the Logs page (stdout/stderr only since #343).Change
logError(message, { error })for stdout andcaptureError(error)for APM. This matchesroutes/handler.ts.captureErroracceptsunknownand wraps non-Errorvalues, so call sites don't each need aninstanceofcheck. Existing callers are unaffected.fireAuthHook, password reset landing, email verification, GitHub/Google OAuth callbacks, OAuth error-redirect build failure,errorComponentfailure, andsafelyCallHook.redirectUrilog inoauthCommon.ts. It is a rejected input, not a caught exception.Test plan
logErrorandcaptureErrorfor each covered handler. All 9 new assertions fail onmainand pass on this branch.vitest run: 1545/1545 passtsc --noEmit, eslint, andnpm run buildare clean🤖 Generated with Claude Code
Note
Low Risk
Observability-only changes in catch blocks; auth behavior and client-facing responses stay the same.
Overview
Auth flows that catch errors internally (magic link landing and token restore, password reset landing, email verification, GitHub/Google OAuth callbacks, OAuth error rendering/redirect fallbacks, and auth/OAuth hooks) no longer rely on
console.erroralone. Each site now callslogErrorso failures still show on the Logs page andcaptureErrorso telemetry-enabled deployments report them to APM, matching the route handler pattern.captureErrornow acceptsunknown, normalizes non-Errorthrows into anError(with safe handling when stringification fails), and tests cover those edge cases. User-facing redirects and responses are unchanged; tests were updated to mock@/telemetryand assert both logging and capture at each handler.Reviewed by Cursor Bugbot for commit c2c802c. Bugbot is set up for automated code reviews on this repo. Configure here.