Skip to content

fix(errors): global error branding via Symbol.hasInstance to fix instanceof checks across bundle entry points - #612

Merged
JakubWorek merged 1 commit into
mainfrom
jakubworek/fix-issue-608
Aug 3, 2026
Merged

JakubWorek merged 1 commit into
mainfrom
jakubworek/fix-issue-608

Conversation

@JakubWorek

Copy link
Copy Markdown
Member

Description

Protocol errors were downgraded to JSON-RPC InternalError (-32603), HTTP 500 and gRPC UNKNOWN whenever they crossed a package entry point.

tsup builds each subpath export as a separate bundle (splitting: false), so every entry inlines its own copy of src/errors/base.ts - 13 distinct A2AError constructors. The instanceof A2AError gate that all wire mapping goes through therefore failed for an error built by a different entry, e.g. a TaskNotFoundError from @a2a-js/sdk/errors reaching the adapter in @a2a-js/sdk/server/express. A2AError now carries a Symbol.for() brand and a Symbol.hasInstance that matches on it, so instanceof no longer depends on constructor identity. Subclasses inherit the check and stay exact — they are matched by class name up the prototype chain, the same identity error.name and the registry tables already key on. One change in src/errors/base.ts fixes all internal check sites plus user-land instanceof TaskNotFoundError; no call site changes.

Verified end to end on the built dist: JSON-RPC blocking/streaming, REST and gRPC all return the correct semantic code, in ESM and CJS. Also covers two cases the duplication caused beyond the report - a consumer bundling two entry points into one output (where the bundler renames the colliding class binding), and two SDK versions installed side by side.

Enabling splitting: true was evaluated as a root-cause fix and rejected: tsup's experimental CJS splitting rewrites the error class bodies into a sequence expression, which defeats JS named evaluation and silently sets error.name to _class2 - turning every semantic error into -32603/500 for every CJS consumer.

Fixes #608 🦕

@JakubWorek
JakubWorek requested a review from a team as a code owner July 31, 2026 11:11
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/errors/base.ts 97.79% 98.02% 🟢 +0.23%
Total 90.98% 90.99% 🟢 +0.01%

Generated by coverage-comment.yml

@JakubWorek
JakubWorek merged commit cc33173 into main Aug 3, 2026
16 checks passed
@JakubWorek
JakubWorek deleted the jakubworek/fix-issue-608 branch August 3, 2026 07:39
bartek-gralewicz added a commit that referenced this pull request Aug 26, 2026
🤖 I have created a release *beep* *boop*
---


## [1.1.0](v1.0.1...v1.1.0)
(2026-08-26)


### Features

* make event bus keep-alive states configurable
([#669](#669))
([f844dad](f844dad)),
closes [#620](#620)


### Bug Fixes

* Add serialization for listTasks input/output parameters.
([#610](#610))
([c863497](c863497))
* clone push notification configs before storing
([#662](#662))
([4d175a0](4d175a0))
* **compat/v0_3/translate:** add null and undefined checks to array and
string fields ([#618](#618))
([108736b](108736b))
* **deps:** replace `uuid` package with `crypto.randomUUID()`
([#665](#665))
([636b060](636b060))
* Do not filter tasks in ListTasks if task state is unspecified
([#622](#622))
([1c6eb32](1c6eb32))
* **errors:** global error branding via Symbol.hasInstance to fix
instanceof checks across bundle entry points
([#612](#612))
([cc33173](cc33173))
* **scripts:** update generate script to use buf and remove obsolete
generateTypes ([#653](#653))
([8bf3cd3](8bf3cd3))
* **server:** send full Task on every v0.3 push trigger
([#658](#658))
([b3afbe4](b3afbe4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: bartek-gralewicz <[email protected]>
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.

Cross-entry A2AError identity makes Express JSON-RPC adapter return InternalError

2 participants