You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat!: unify A2AError hierarchy with transport specific subclasses (#587)
# Description
**Error Handling Refactor and Unification**
* All error classes now form a shared, transport-agnostic hierarchy with
A2AError as the base and semantic subclasses (e.g., TaskNotFoundError,
RequestMalformedError). Per-transport variants (e.g.,
RestTaskNotFoundError, GrpcTaskNotFoundError, JsonRpcTaskNotFoundError)
extend their semantic parent and carry transport-native context (HTTP
status/headers/cause, gRPC status/status-details-bin, JSON-RPC envelope
code/data). Type guards isRestError / isGrpcError / isJsonRpcError
narrow at catch time so callers keep instanceof TaskNotFoundError and
simultaneously get typed access to transport fields. Closes#317.
* Errors live at two dedicated subpaths: @a2a-js/sdk/errors (pb-free,
Workers-safe — base + semantic + REST + JSON-RPC) and
@a2a-js/sdk/errors/grpc (requires @bufbuild/protobuf for
grpc-status-details-bin encode/decode). The SDK root and /client /
/server no longer re-export errors, so non-gRPC consumers don't pull in
the pb peer dep.
* All transport implementations (rest, grpc, json-rpc, and legacy
variants) now use centralized error mapping functions from the new
modules (fromRestErrorBody, fromGrpcError, fromJsonRpcErrorResponse,
toRestErrorBody, toJsonRpcError, buildGrpcErrorMetadata, restStatusFor,
grpcStatusFor) instead of custom or scattered logic. Adding a new error
is one row in A2A_ERROR_SPECS — all wire mappings derive from it.
* The v0.3 compat layer replaces LegacyA2AError with a thin facade over
the new hierarchy that keeps the classic A2AError.taskNotFound(id) / new
A2AError(code, msg, data?) API. Wire codes without a v1.0 semantic twin
(PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND) are preserved via
JsonRpc*Error.envelopeCode, so v0.3 clients keep seeing the same numeric
codes on the wire.
**Transport Implementation Simplification**
* Removed old error mapping methods from RestTransport, GrpcTransport,
JsonRpcTransportHandler, and their v0.3 compat counterparts in favor of
the centralized helpers, reducing code duplication and eliminating 6+
parallel error.name-keyed lookup tables.
* Added helpers to collect HTTP headers and provide richer error context
in REST transport errors.
* Deleted src/errors.ts (354 lines) and src/server/grpc/error_details.ts
(67 lines); folded into the new src/errors/ module.
**Build-tests Fix**
* The existing test-build script (esbuild --platform=neutral) never
actually enforced Workers-safe boundaries — platform=neutral bundles
Node-only modules silently, and CI's npm ci installs devDependencies
(which include @grpc/grpc-js and @bufbuild/protobuf), so the check was a
no-op. Added scripts/checkWorkersSafeBundles.js that fails if any
Workers-safe bundle inlines @grpc/grpc-js or @bufbuild/protobuf.
TDD-verified (goes RED when errors/grpc is re-exported from the pb-free
barrel, GREEN with the split).
**Documentation and Migration Guide Updates**
* Updated the migration guide to explain the new error class structure,
the two subpath entrypoints (@a2a-js/sdk/errors,
@a2a-js/sdk/errors/grpc), and the transport-specific catch-site pattern
with type guards, with code examples for the new patterns.
Closes#583#317 🦕
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ npm install express
44
44
45
45
### For gRPC Usage
46
46
47
-
If you plan to use the GRPC transport (imports from `@a2a-js/sdk/server/grpc`or `@a2a-js/sdk/client/grpc`), you must install the required peer dependencies:
47
+
If you plan to use the GRPC transport (imports from `@a2a-js/sdk/server/grpc`, `@a2a-js/sdk/client/grpc`, or the gRPC-specific error helpers in `@a2a-js/sdk/errors/grpc`), you must install the required peer dependencies:
0 commit comments