Skip to content

fix(sveltekit): Handle SvelteKit 3 error kinds in handleErrorWithSentry - #23651

Merged
chargome merged 3 commits into
developfrom
fix/sveltekit-3-handle-error
Aug 27, 2026
Merged

fix(sveltekit): Handle SvelteKit 3 error kinds in handleErrorWithSentry#23651
chargome merged 3 commits into
developfrom
fix/sveltekit-3-handle-error

Conversation

@chargome

@chargome chargome commented Aug 26, 2026

Copy link
Copy Markdown
Member

SvelteKit 3 changed the handleError input to { kind, error, event } - status moved onto the error, and expected errors thrown with error(...) now reach the hook too. Reading the old status meant capturing framework 404s and every intentional error(400, …) on Kit 3, plus a SvelteKit deprecation warning per error in dev.

The wrapper now branches on kind and applies the SDK's usual rule: capture unexpected errors always, app and framework errors only at 5xx, skip validation errors. Hook types are declared structurally because Kit 3 moved them to @sveltejs/kit/hooks, which doesn't resolve on Kit 2. SvelteKit 1.x/2.x behaviour is unchanged.

Fixes #23650

SvelteKit 3 changed the `handleError` input to `{ kind, error, event }`: `status` moved onto
the error, and expected errors thrown with `error(...)` now reach the hook too. Reading the old
`status` meant capturing framework 404s and every intentional `error(400, …)` on Kit 3, plus a
SvelteKit deprecation warning per error in dev.

Branch on `kind` and apply the SDK's usual rule: capture unexpected errors always, app and
framework errors only at 5xx, skip validation errors. Declare the hook types structurally, since
Kit 3 moved them to `@sveltejs/kit/hooks`, which doesn't resolve on Kit 2.

SvelteKit 1.x/2.x behaviour is unchanged.

Fixes #23650
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome chargome self-assigned this Aug 26, 2026
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.63 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.65 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.56 kB - -
@sentry/browser (incl. Tracing, Replay) 88.11 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.51 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.82 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.51 kB - -
@sentry/browser (incl. Feedback) 45.79 kB - -
@sentry/browser (incl. sendFeedback) 33.35 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.84 kB - -
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.88 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.12 kB - -
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.01 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73 kB - -
CDN Bundle (incl. Tracing, Replay) 86.62 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.52 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.33 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.82 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.51 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.42 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.68 kB - -
@sentry/nextjs (client) 53.41 kB - -
@sentry/sveltekit (client) 49.08 kB - -
@sentry/core/server 65.15 kB -0.23% -149 B 🔽
@sentry/core/browser 52.37 kB - -
@sentry/node 122.69 kB +0.18% +214 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.22 kB - -
@sentry/node - without tracing 87.73 kB +0.11% +93 B 🔺
@sentry/node - without channel injection 102.36 kB +0.19% +194 B 🔺
@sentry/aws-serverless 95.88 kB +0.1% +92 B 🔺
@sentry/cloudflare (withSentry) - minified 199.61 kB - -
@sentry/cloudflare (withSentry) 495.94 kB - -

View base workflow run

Comment thread packages/sveltekit/src/client/handleError.ts
Explain why the wrapper's double casts can't be narrowed, and replace the timeout race in the
4xx e2e test with a concrete signal, per the repo's testing guidance.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6bf4f27. Configure here.

@chargome
chargome marked this pull request as ready for review August 27, 2026 08:22
@chargome
chargome requested a review from a team as a code owner August 27, 2026 08:22
@chargome
chargome requested review from Lms24, nicohrubec and s1gr1d and removed request for a team August 27, 2026 08:22
Comment thread packages/sveltekit/src/common/handleErrorTypes.ts

@nicohrubec nicohrubec 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.

lgtm, just two minor style notes/questions

Comment thread packages/sveltekit/src/server-common/handleError.ts Outdated
Comment thread packages/sveltekit/src/server-common/handleError.ts Outdated
Comment thread packages/sveltekit/src/client/handleError.ts Outdated
Comment thread packages/sveltekit/src/client/handleError.ts
Comment thread packages/sveltekit/src/client/handleError.ts Outdated
Comment thread packages/sveltekit/src/client/handleError.ts Outdated
Comment thread packages/sveltekit/src/common/handleErrorTypes.ts Outdated
Model the `handleError` input as a discriminated union, so `status` and `message` can't be read
on a SvelteKit 3 input where they only exist as deprecated dev-only getters - the type system now
enforces what a comment used to.

Skip validation errors on their `kind` rather than relying on SvelteKit always giving them a 400,
share the capture decision between server and client, and rename the legacy check to say what it
actually does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome
chargome merged commit 31da830 into develop Aug 27, 2026
539 of 542 checks passed
@chargome
chargome deleted the fix/sveltekit-3-handle-error branch August 27, 2026 15:51
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.

SvelteKit 3: handleErrorWithSentry captures expected errors

3 participants