Skip to content

feat: add a server function error handler - #2262

Merged
birkskyum merged 4 commits into
solidjs:mainfrom
adipascu:feat/server-fn-error-hook
Jul 28, 2026
Merged

feat: add a server function error handler#2262
birkskyum merged 4 commits into
solidjs:mainfrom
adipascu:feat/server-fn-error-hook

Conversation

@adipascu

@adipascu adipascu commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

  • Addresses an existing open issue: fixes #000
  • Tests for the changes have been added (for bug fixes / features)

What is the current behavior?

handleServerFunction catches everything a server function throws and writes it straight into the response. Nothing else observes it, so the crash is invisible to monitoring, and whatever was thrown reaches the client as-is.

What is the new behavior?

A new serverFunctions.onError option names a module whose default export is called with the thrown value before it is serialized. Returning a value replaces what is sent, returning undefined changes nothing.

solidStart({ serverFunctions: { onError: "src/server-fn-error.ts" } });

Naming the module in the config rather than registering a handler at runtime keeps the app in sole control of it, so no dependency can reach the running server and take over reporting. It follows serialization.plugins from #1474, with its own virtual module because this one is bundled into the server only and may import a monitoring SDK.

How other frameworks do this:

  • SvelteKit handleError, which observes and replaces: docs (src). Same handler(...) ?? fallback shape as this PR.
  • Next.js onRequestError, observe only: docs (src)
  • React Router handleError, observe only: docs (src)
  • Nitro error hook, observe only: docs (src)
  • TanStack Start has no dedicated hook. Global functionMiddleware wraps every server function, so an app catches around next() itself: docs (src)

Replacing matters for adapters whose runtime wraps failures, such as Effect's FiberFailure. Unwrapping here keeps a Response thrown through the wrapper recognised as control flow by the x instanceof Response branch.

@netlify

netlify Bot commented Jul 28, 2026

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit a474969
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a68f081b770200009ae0246
😎 Deploy Preview https://deploy-preview-2262--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 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a474969

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/start Minor

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/start@2262

commit: a474969

@adipascu
adipascu force-pushed the feat/server-fn-error-hook branch from f25d012 to acccfe0 Compare July 28, 2026 15:42
Comment thread packages/start/src/fns/handler.ts Outdated
@adipascu adipascu changed the title feat: allow a server function error to be observed and replaced before serialization feat: add a server function error handler Jul 28, 2026
@adipascu
adipascu force-pushed the feat/server-fn-error-hook branch 4 times, most recently from 4f304fb to 2d14f17 Compare July 28, 2026 17:24
@adipascu
adipascu marked this pull request as ready for review July 28, 2026 17:24
@adipascu
adipascu force-pushed the feat/server-fn-error-hook branch from 2d14f17 to ce68392 Compare July 28, 2026 17:29
Comment thread packages/start/src/fns/error-handler.ts Outdated
@adipascu
adipascu marked this pull request as draft July 28, 2026 18:00

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

AI works wonders

@adipascu
adipascu marked this pull request as ready for review July 28, 2026 18:09
@adipascu

Copy link
Copy Markdown
Contributor Author

Thanks for the #1474 pointer, serverFunctions.onError came out much cleaner than the setter. Branch is green and up to date, and good to merge from my side whenever someone with the rights can.

@birkskyum
birkskyum merged commit bac24b2 into solidjs:main Jul 28, 2026
11 checks passed
brenelz added a commit that referenced this pull request Jul 29, 2026
Brings the v2 rc line (through 2.0.0-rc.6) into the Solid 2 branch.

Ported main features onto the Solid 2 architecture:
- Server-function error handler (#2262): wired through
  handleServerFunctionRequest's transformResult hook and the
  solid-start:server-fn-error-handler virtual module.
- Custom seroval plugins (#2250): serialization.plugins now feeds the
  @solidjs/web codec on both the client transport and the server handler.
- ~ alias fix for workspace packages (#2239): adopted appRootAlias in
  place of the global resolve.alias entry.
- Dev toolbar (#2049, replaces the dev overlay): ported to Solid 2
  (Errored/Loading, onSettled, two-arg createEffect, draft-mutation
  stores, terracotta 2 subpath imports, @solidjs/web Portal/Dynamic/JSX,
  createMemo(async) instead of createResource). Protocol-specific pieces
  (SerovalChunkReader, body-format markers) moved local to the toolbar.
- Deferred stream response via h3 iterable() (#2231), StartHandler type
  (#2234), routerLoad restore (#2228), nonce on streaming redirect
  script (#2252), ResizeObserver-loop filter (#2240) all kept.

Kept deleted (superseded by vite-plugin-solid / @solidjs/web /
@solidjs/router server-function integration): fs-routes tree-shake,
manifest.ts, directives, fns serialization/registration/shared and their
specs. Fixes main landed in those files (#2249, #2238, #2243, #2245,
#2241, #2261) live upstream now and are tracked for porting there.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants