fix(core): don't console.error the raw query error in handleFallbackJoin - #11206
Open
Didactora wants to merge 1 commit into
Open
fix(core): don't console.error the raw query error in handleFallbackJoin#11206Didactora wants to merge 1 commit into
Didactora wants to merge 1 commit into
Conversation
The caught error is passed to `logger.error` instead of being printed with a
bare `console.error`, so it goes through the configured logger like every other
diagnostic in this file.
Why it matters: the error reaching this catch is usually a driver error, and for
Drizzle a `DrizzleQueryError`'s message is built unconditionally as
`Failed query: <sql>\nparams: <params>`. `handleFallbackJoin` runs on the
session-read path (`findSession` passes `join: { user: true }`), on the OAuth
callback (`findOAuthUser`) and on sign-in/password-reset (`findUserByEmail` with
`includeAccounts`), so on a transient database fault that bare call writes query
parameters straight to stderr - past any `logger` the consumer configured. On a
serverless host stderr is the log store, so those parameters are retained.
The line above it already logs the same failure through `logger`, so nothing is
lost by routing the error the same way: consumers who want the full error still
get it as a structured field, and consumers who sanitize their logger now
actually get sanitization.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
@Didactora is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
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.
What
handleFallbackJoincatches a storage fault, logs it throughlogger.error, and then calls a bareconsole.error(error)before rethrowing. This moves the caught error into thelogger.errorcall that is already there and drops the bareconsolecall.} catch (error) { logger.error(`Failed to query fallback join for model ${modelName}:`, { where, limit: joinConfig.limit, + error, }); - console.error(error); throw error; }Why
The error reaching this catch is normally a driver error. For Drizzle,
DrizzleQueryError's message is built unconditionally inqueryWithCacheas:handleFallbackJoinis on well-travelled paths —findSessionpassesjoin: { user: true }, so it runs on every session read;findOAuthUserruns on the OAuth callback;findUserByEmailwithincludeAccountsruns on sign-in and password reset. So on a transient database fault, the bareconsole.errorwrites query parameters — a user id on the session leg, an email on a user lookup — straight to stderr, bypassing whateverloggerthe consumer configured.That matters most on serverless hosts, where stderr is the log store and the lines are retained. A consumer who deliberately installs a
logger.loghandler to strip identifiers currently has no way to reach this one call site: it is not routed through the logger, and it is inside a closure the adapter option cannot wrap.Why this shape rather than deleting the line
The diagnostic is worth keeping — it is just going to the wrong place. Passing
erroras a structured field on thelogger.errorimmediately above it preserves the information for anyone who wants it, routes it through the same logger as every other diagnostic in this file, and lets a consumer who sanitizes their logger actually get sanitization. No information is lost; only the bypass is.Notes
throw errorbelow is untouched, so callers see exactly the same failure.main(packages/core/src/db/adapter/factory.ts), and the same block is present in the published1.6.23and1.7.3dists.Summary by cubic
Routes the fallback join error through the configured
logger.errorinstead of a bareconsole.error, so driver error messages containing query parameters no longer bypass consumer log sanitization and write to stderr (which is the log store on serverless hosts).logger.errorcall, so no diagnostic information is lost.handleFallbackJoinruns on session reads, OAuth callbacks, and sign-in and password-reset lookups.throw errorbelow is untouched, so callers see the same failure.Written for commit bc58820. Summary will update on new commits.