fix: use name-based fallback in get_status/get_message when SvelteKitError crosses a bundle boundary#15778
Conversation
…le SvelteKitError identity When adapter-node bundles its own copy of @sveltejs/kit, instanceof checks fail because the error was created from one class instance and checked against another. Fall back to error.name comparison, which survives any bundle boundary. Both SvelteKitError and HttpError now set this.name explicitly in their constructors.
🦋 Changeset detectedLatest commit: b134596 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Hey Elliott, thanks for the suggestion on the issue. I went down that path first (see #15776) and want to flag what I ran into. Adapter-node bundles SvelteKit twice, in two separate passes:
The error comes from copy A and gets caught against copy B. Marking The name-based fallback in this PR sidesteps both copies. Both classes set Happy to take it in a different direction if you'd rather chase the source-level fix and accept the deployment trade-off. Let me know which way you want to go. |
|
Friendly ping — this PR has been ready for review with all CI passing for 9 days. The fix uses a name-based fallback approach (as suggested in the issue) to handle SvelteKitError crossing bundle boundaries. Ready to merge whenever you have bandwidth! 🚀 |
closes #15755
get_statusandget_messageinutils/error.jsuseinstanceof SvelteKitErrorto decide whether to return the error's status code and text. When adapter-node bundles its own copy of@sveltejs/kit, the error object was created by one copy of the class but checked against another, soinstanceoffails and the fallback 500 is returned instead of the real status.The fix has two parts. First, both
SvelteKitErrorandHttpErrornow setthis.namein their constructors. That's a plain string on the instance, so it crosses any bundle boundary without issues. Second,get_statusandget_messagefall back to checkingerror.namewheninstanceoffails, the same way Node.js itself useserror.codestrings instead of class identity for system errors.A previous attempt (#15776) tried to mark
@sveltejs/kit/nodeas external in the adapter-node rollup config. That didn't work because the second rollup pass inadapter/index.jsbundles@sveltejs/kitfrom devDependencies anyway, leaving two separate class instances regardless.