Skip to content

Error serialization issue #5783

@oguzgelal

Description

@oguzgelal

Which project does this relate to?

Start

Describe the bug

Errors thrown on server side does not serialize correctly. Here's an example:

class TestError extends Error {
  constructor(message: string = 'Test error') {
    super(message)
    this.name = 'TestError' // ← Error name set to 'TestError'
  }
}

export const testError = createServerFn().handler(async () => {
  throw new TestError('This is a test')
})

and on the client side:

const testErrorMutation = useServerFn(testError);

// ...

<Button
  onClick={async () => {
    try {
      await testErrorMutation()
    } catch (err) {
      const error = err as Error
      console.log(error.name) // prints 'Error' instead of 'TestError'
    }
  }}
>
  Throw server error
</Button>

While the error thrown has the name 'TestError', this information gets lost in serialization/deserialization.

Your Example Website or App

https://stackblitz.com/edit/github-egpnw7wu-6dmvze6t?file=src%2Froutes%2Findex.tsx

Steps to Reproduce the Bug or Issue

N/A

Expected behavior

It should print 'TestError'

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.132.0
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 141.0.7390.122
  • Bundler: Vite
  • Bundler Version: 7.1.7

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions