Skip to content

fix: narrow the router error before reading its fields - #57

Merged
amrtgaber merged 1 commit into
mainfrom
fix/error-boundary-unknown-error
Oct 9, 2026
Merged

amrtgaber merged 1 commit into
mainfrom
fix/error-boundary-unknown-error

Conversation

@amrtgaber

Copy link
Copy Markdown
Contributor

Summary

@tanstack/router-core 1.171.28 changed the type of the error passed to route error components from Error to unknown. The new ErrorBoundaryTypes interface defaults to { error: unknown }, since JavaScript can throw anything. The error boundary read error.message and error.stack directly, which no longer typechecks.

It now reads message and stack only from an actual Error, and stringifies anything else, so the structured log keeps its shape either way. The fix compiles on both the old and new router types.

Why not augment ErrorBoundaryTypes to say error: Error? That would only restore the old assumption. If something throws a non-Error (throw undefined), the error boundary itself would crash reading .message.

Why now

Once Dependabot's next minor/patch group bumps the router past 1.171.28, the typecheck fails on exactly this line. Fixing it now keeps that group from going red.

Verification

  • Lint, format, typecheck, tests and build pass on this branch
  • With the router updated to the latest in-range version in a scratch checkout (router-core 1.171.34), the typecheck passes

@tanstack/router-core 1.171.28 types the error passed to route error
components as unknown (ErrorBoundaryTypes defaults to { error: unknown }),
since anything can be thrown. Reading error.message and error.stack stops
typechecking once the router resolves to that version.

Read message and stack only from an actual Error, and stringify anything
else, so the structured log keeps its shape either way.
@amrtgaber
amrtgaber merged commit 17986ad into main Oct 9, 2026
2 checks passed
@amrtgaber
amrtgaber deleted the fix/error-boundary-unknown-error branch October 9, 2026 02:08
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