Repository navigation
fix(core): recognize PluginRouteError from a separate emdash instance - #3741
Conversation
Under `astro dev`, Vite pre-bundles a plugin package for SSR with `emdash` kept external, so the plugin's PluginRouteError can come from a different module instance than the one the route dispatcher imports. The `instanceof` check then fails, and a deliberate 4xx error from the plugin reaches the client as a generic 500 INTERNAL_ERROR. Match route errors by shape as well as by class. Fixes emdash-cms#3588 Co-Authored-By: Claude Opus 5.5 <[email protected]>
🦋 Changeset detectedLatest commit: eab932f The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
This is the right fix for the reported cross-instance PluginRouteError problem. Under astro dev, Vite can load the plugin's emdash import and the route handler's internal ./route-error.js as separate module instances, so instanceof identity fails and the error collapses to a generic 500.
The implementation is minimal and correct:
packages/core/src/plugins/route-error.tsaddsisPluginRouteError(), keeping the fastinstanceofpath and falling back to a structural check (Errornamed"PluginRouteError"with a stringcodeand numericstatus).packages/core/src/plugins/routes.tsreplaceserror instanceof PluginRouteErrorwithisPluginRouteError(error), so a foreign copy still returns its intended code, status, message, and details.- The tests are real regression tests, not tautologies: one throws a separate
PluginRouteError-shaped class and asserts the shaped error reaches the client; another confirms that an error that only borrows the name still becomesINTERNAL_ERROR. - The changeset is proportional and user-facing, naming the observable behavior and environment.
I also checked the tree for other instanceof PluginRouteError sites. The only remaining one is in packages/cloudflare/src/plugins/ai-search.ts, but the thrower and catcher there share the same imported PluginRouteError binding, so the cross-instance bug does not apply there. No AGENTS.md convention issues (no new UI strings, SQL, content-table queries, logged-out query paths, or comment violations).
|
I have read the CLA Document and I hereby sign the CLA |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
Thanks for contributing to EmDash! 🎉 Join the EmDash Discord, then run |
What does this PR do?
Under
astro dev, a native plugin route that throwsPluginRouteError(for examplePluginRouteError.badRequest("…")) reaches the client as a generic 500INTERNAL_ERRORinstead of the error's code, status, and message.Vite pre-bundles the plugin package for SSR with
emdashkept external, so the plugin'sPluginRouteErrorcan come from a different module instance than the onePluginRouteHandlerimports. Theerror instanceof PluginRouteErrorcheck inroutes.tsthen fails, and the error falls through to the unknown-error branch.This adds
isPluginRouteError()next to the class. It keeps theinstanceoffast path and also accepts anErrornamedPluginRouteErrorwith a stringcodeand numericstatus, so a route error from another copy of the module is still reported as the plugin intended. An ordinary error that only borrows the name is still treated as unknown.#3602also touches plugin route errors, but it changes howdispatchPluginApiRequestbuilds the response (passingdetailsthrough), so the two changes are independent.Closes #3588
Type of change
Checklist
pnpm typecheckpasses (rantsgo --noEmitinpackages/core)pnpm lintpasses (ran type-awareoxlint --deny-warningson the changed files)pnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain. — n/a, no UI stringsAI-generated code disclosure
Screenshots / test output
Not applicable (no UI change).
The new regression test in
packages/core/tests/unit/plugins/routes.test.tsthrows aPluginRouteError-shaped error from a separate class, as a second module instance would:1 failed | 52 passed (53)(the new test gets500 INTERNAL_ERROR)53 passed (53)A second new test checks that an
Errorthat only setsname = "PluginRouteError"still returns500 INTERNAL_ERROR.