Stop reporting routine 4xx to Sentry, and report the DB errors we swallowed - #684
Open
AchrafReyani wants to merge 1 commit into
Open
AchrafReyani wants to merge 1 commit into
AchrafReyani wants to merge 1 commit into
Conversation
…llowed Three database failures in the client-auth path were logged with console.error and then forgotten, so production never saw them: the migration run in server.ts, the startup reachability probe, and the runtime client lookup. Each now captures alongside the log it already wrote, tagged with a reason. The lookup site matters most — the 503 it leads to is already reported, but with only the token hash, never the error the database actually returned. The onError hook, meanwhile, reported everything it saw, including the NOT_FOUND from bots hitting /favicon.ico and the parse error from a malformed body. Those are caller errors and they bury the ones we want. Elysia puts an error's status in a different place depending on where it came from — `status` on its own errors, a numeric `code` on an ApolloThrowable, and otherwise only what it has already put on `set` — so errorStatus reads all three in that order and the hook skips a 4xx. An error whose status cannot be read is unexpected, so it is still reported rather than dropped. No change to any HTTP response: the hook still returns nothing and Elysia produces its normal error body and status. Fixes OpenFn#554 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Short Description
Reports the three database errors the client-auth path was swallowing, and stops sending routine 4xx to Sentry.
Fixes #554
Implementation Details
Both halves live in the same two files, as the issue notes.
1. The three swallowed DB errors. Each
console.errord and moved on; each now captures next to the log it already wrote, tagged with areasonso the three are distinguishable in Sentry:platform/src/server.ts—runMigrations()failuremigrations-failedplatform/src/auth/instance-auth.ts— startup DB probedb-unreachableplatform/src/auth/instance-auth.ts— runtime client lookupclient-lookup-errorThe lookup site is the one worth calling out: the 503 it leads to is already captured as
client-store-unavailable-503, but that capture carries only the token hash — never the error the database actually returned.captureExceptionwas already imported in both files, so no new imports were needed (server.tshas had it since the hook was added, so that part of the acceptance criteria was already satisfied).2. Skipping 4xx in the
onErrorhook. The one thing here that isn't a one-liner is reading the status, because Elysia puts it in a different place depending on where the error came from. I probed each case rather than guessing:error.statuscodeset.statusNOT_FOUND404"NOT_FOUND"200(untouched)VALIDATION422"VALIDATION"422PARSE400"PARSE"400ApolloThrowable(429, …)429500throw new Error(…)"UNKNOWN"500So
errorStatustakes the first number amongerror.status,code,set.status, and the hook skips when that is a 4xx. Note theNOT_FOUNDrow —set.statusalone would read as200, which is why the order matters. An error whose status can't be read is by definition unexpected, so it is still reported.errorStatusandisClientErrorare exported fromserver.tspurely so the tests can drive them against real Elysia contexts instead of hand-written stand-ins; happy to make them module-private if you'd rather.No HTTP response changes: the hook still returns nothing, so Elysia produces its normal body and status. Verified below.
Verification
Environment: Windows, bun 1.4.2, Postgres 16 in Docker and poetry 2.3.2 / Python 3.11 set up to match the
bunCI job.Reproduced first, on
main. A local HTTP server standing in for Sentry (SENTRY_DSN=http://…@127.0.0.1:9999/1), counting envelopes. Five requests —GET /favicon.ico,GET /wp-admin,POST /services/test_errors {"trigger":"RATE_LIMIT"},{"trigger":"UNEXPECTED"}, and a malformed JSON body:Same five requests on this branch — identical status codes, nothing reported:
The DB captures, end to end. Booted with
APOLLO_CLIENTS_DB_URL=postgres://apollo:apollo@127.0.0.1:1/nopeso the migration run and the startup probe both fail:On
mainthe same boot reports nothing.Tests. Six added — an
errorStatus/isClientErrortable built from contexts captured off a real ElysiaonError(so it's Elysia's behaviour, not my memory of it), the unreadable-status case, a 404 through the real server proving the hook consults the guard, theclient-lookup-errorcapture, and the two startup failures. All six fail onmainand pass here.bun test platform/test, with Postgres and poetry wired up as in CI:The 4 failures are the same on both and are this machine, not the change: they shell out to
pkill, which Windows doesn't have (error: Executable not found in $PATH: "pkill").AI Usage
🤖 Generated with Claude Code