Skip to content

fix(cloudflare): Reject unknown keys in options callbacks - #23290

Merged
isaacs merged 3 commits into
developfrom
jp/cloudflare-types
Aug 18, 2026
Merged

fix(cloudflare): Reject unknown keys in options callbacks#23290
isaacs merged 3 commits into
developfrom
jp/cloudflare-types

Conversation

@JPeer264

@JPeer264 JPeer264 commented Aug 11, 2026

Copy link
Copy Markdown
Member

Problem

It seemed that TypeScript didn't bother on wrong types in the options. This enables it and the following throws now a TS error:

withSentry(() => ({ something: null }), handler)

It also seemed that we forgot to add serverName in the available options for Cloudflare

Solution

Some workaround to make the types stricter within functions: TS Playground

It also seems to be known: microsoft/TypeScript#7547 (comment)


Clanker description:

TypeScript's excess property check does not survive a function boundary, so typos in the options callback went unreported:

withSentry(() => ({ dsn, tracesSampleRte: 1 }), handler) // compiled fine

StrictCloudflareOptions<O> infers the returned literal into O and intersects it with a never map over its unknown keys, restoring the error. Applied to every entry point taking options.

Note this is top level only, nested option objects stay unchecked, and it also rejects a pre-built object carrying extra keys, which a plain excess property check would allow.

Two bugs this surfaced: the Hono Cloudflare middleware spread the middleware-only shouldHandleError into the SDK options, and serverName was missing from CloudflareOptions despite being consumed by ServerRuntimeClient.

A plain `CloudflareOptions` parameter already rejects unknown keys when the
caller writes a direct object literal, which is why it is enough everywhere
else. That check does not survive a function boundary though, and since `env`
only exists at request time, a callback is the only way to configure these
APIs — so typos went unreported:

    withSentry(() => ({ dsn, tracesSampleRte: 1 }), handler) // compiled fine

`StrictCloudflareOptions<O>` rebuilds the check for the callbacks only: it
infers the returned literal into `O` and intersects it with a `never` map over
its unknown keys. A function-rejecting branch keeps "returned the options
factory instead of calling it" an error, which the intersection would otherwise
allow. The object forms stay on plain `CloudflareOptions`.

Note this is top level only — nested option objects stay unchecked — and it
also rejects a pre-built object carrying extra keys, which a plain excess
property check would allow.

Two bugs this surfaced: the Hono Cloudflare middleware spread the
middleware-only `shouldHandleError` into the SDK options, and `serverName` was
missing from `CloudflareOptions` despite being consumed by `ServerRuntimeClient`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JPeer264 JPeer264 self-assigned this Aug 11, 2026
@JPeer264
JPeer264 requested review from a team as code owners August 11, 2026 13:23
@JPeer264
JPeer264 requested review from chargome, isaacs, mydea and s1gr1d and removed request for a team August 11, 2026 13:23
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.3 kB - -
@sentry/browser - with treeshaking flags 28.47 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.81 kB - -
@sentry/browser (incl. Tracing) 48.58 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.59 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.46 kB - -
@sentry/browser (incl. Tracing, Replay) 87.98 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.36 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.7 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.39 kB - -
@sentry/browser (incl. Feedback) 47.65 kB - -
@sentry/browser (incl. sendFeedback) 35.13 kB - -
@sentry/browser (incl. FeedbackAsync) 40.28 kB - -
@sentry/browser (incl. Metrics) 31.24 kB - -
@sentry/browser (incl. Logs) 31.52 kB - -
@sentry/browser (incl. Metrics & Logs) 32.15 kB - -
@sentry/react 32.09 kB - -
@sentry/react (incl. Tracing) 50.77 kB - -
@sentry/vue 35.34 kB - -
@sentry/vue (incl. Tracing) 50.54 kB - -
@sentry/svelte 30.33 kB - -
CDN Bundle 31.61 kB - -
CDN Bundle (incl. Tracing) 48.9 kB - -
CDN Bundle (incl. Logs, Metrics) 33.8 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.82 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.31 kB - -
CDN Bundle (incl. Tracing, Replay) 86.48 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.31 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.12 kB - -
CDN Bundle - uncompressed 93.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.75 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.44 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.08 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.01 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.71 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.37 kB - -
@sentry/nextjs (client) 53.29 kB - -
@sentry/sveltekit (client) 49 kB - -
@sentry/core/server 65.38 kB - -
@sentry/core/browser 51.72 kB - -
@sentry/node 117.01 kB +0.02% +22 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 81.45 kB +0.03% +21 B 🔺
@sentry/aws-serverless 90.95 kB +0.03% +23 B 🔺
@sentry/cloudflare (withSentry) - minified 213.98 kB - -
@sentry/cloudflare (withSentry) 528.93 kB - -

View base workflow run

Comment thread packages/hono/src/cloudflare/middleware.ts
@github-actions

Copy link
Copy Markdown
Contributor

👋 @isaacs, @mydea, @chargome, @s1gr1d — Please review this PR when you get a chance!

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good.

@isaacs
isaacs enabled auto-merge (squash) August 18, 2026 22:23
@isaacs
isaacs merged commit cef14dc into develop Aug 18, 2026
82 of 83 checks passed
@isaacs
isaacs deleted the jp/cloudflare-types branch August 18, 2026 22:35
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.

2 participants