Skip to content

Add a hook to observe server function errors before serialization#2192

Closed
adipascu wants to merge 1 commit into
solidjs:mainfrom
adipascu:feat/server-fn-error-hook
Closed

Add a hook to observe server function errors before serialization#2192
adipascu wants to merge 1 commit into
solidjs:mainfrom
adipascu:feat/server-fn-error-hook

Conversation

@adipascu

@adipascu adipascu commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

When a server function throws, the handler in packages/start/src/fns/handler.ts catches the error, sets X-Error, and serializes it into the response for the calling client. No server-side error hook ever fires, so genuine crashes inside server functions are invisible to monitoring (Sentry and friends): the platform error hooks (for example Nitro's error hook) only see errors that escape the handler, and these never do.

The result is that a production server function can crash on every call while dashboards stay green, and the only signal is users reporting a generic failure state.

Prior art in other frameworks

  • SvelteKit has handleError, called only for unexpected errors (expected error() throws skip it), letting apps report to monitoring and return a sanitized user-safe representation. This expected-vs-unexpected split is exactly what server-function consumers need here too.
  • Next.js has onRequestError in instrumentation.ts, invoked for server errors including Server Actions (routeType: 'action'), designed for custom observability providers.
  • TanStack Start supports global server-function middleware via registerGlobalMiddleware, which wraps every server function and can observe failures.

Proposal

Call an app-registered global hook from the handler's catch, before serialization, skipping thrown Responses since those are control flow (redirects, forbidden):

if (!(x instanceof Response)) (globalThis as any).__reportServerFnError?.(x);

An app can then register globalThis.__reportServerFnError from its server entry (or a Nitro plugin) and forward to its monitoring SDK.

Status

Draft on purpose: the global hook is the minimal shape that solves the problem, and I am happy to rework it into whatever API surface you prefer (an option on the handler, an exported setServerFnErrorHandler, an event on the app instance, or a SvelteKit-style handleError in the server entry). We currently maintain this as a pnpm patch in production alongside #2159 and would love to drop both.

@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit 8a09b9d
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a586d6b76603600071b996a
😎 Deploy Preview https://deploy-preview-2192--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8a09b9d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/start@2192
npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/vite-plugin-nitro-2@2192

commit: 8a09b9d

@adipascu adipascu force-pushed the feat/server-fn-error-hook branch from 5629754 to 8a09b9d Compare July 16, 2026 05:34
@adipascu adipascu closed this Jul 16, 2026
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.

1 participant