Skip to content

grpc-js: map handler errors with code OK to UNKNOWN - #3130

Closed
Ayush701-code-zm wants to merge 1 commit into
grpc:masterfrom
Ayush701-code-zm:cursor/fix-server-error-ok-status-19d9
Closed

Ayush701-code-zm wants to merge 1 commit into
grpc:masterfrom
Ayush701-code-zm:cursor/fix-server-error-ok-status-19d9

Conversation

@Ayush701-code-zm

Copy link
Copy Markdown

Fixes #3124

If a server handler passes an error whose code is Status.OK (for example cb({ code: grpc.status.OK, details: '...' })), serverErrorToStatus copied code 0, so the server ended the call with OK and no message. The client then reported UNIMPLEMENTED: No message received and the original details were lost.

This maps a truthy error with code OK to Status.UNKNOWN and keeps the details and metadata, which matches grpc-go (grpc/grpc-go#6430). Errors with any other valid code behave as before.

Since serverErrorToStatus is shared, this covers unary and client streaming callbacks and the error event on server streaming and bidi streams. Tests for all four are added in test/test-server-errors.ts.

Tested with npm run compile and the server test files in grpc-js (107 passing, 2 pending as before).

When a server handler passes an error object with code Status.OK (0) to
its callback, sending it as-is would turn the error into a success
status. This is contradictory and usually indicates an application bug.

Previously, the client would receive OK with no message, which then
resulted in UNIMPLEMENTED: No message received - hiding the actual
error details.

This fix maps such errors to Status.UNKNOWN while preserving the
original details and metadata, matching the behavior of grpc-go
(see grpc/grpc-go#6430).

The fix applies to all handler types that use serverErrorToStatus:
- Unary handlers (callback path)
- Client streaming handlers (callback path)
- Server streaming handlers (error event on writable stream)
- Bidirectional streaming handlers (error event on duplex stream)

Fixes: grpc#3124
Co-authored-by: Ayush701-code-zm <Ayush701-code-zm@users.noreply.github.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Ayush701-code-zm / name: Ayush Anand (1c1f684)

@murgatroid99

Copy link
Copy Markdown
Member

The current behavior is correct. No fix is needed.

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.

grpc-js server: an error passed to a handler callback with code: Status.OK is sent as OK, and the client sees UNIMPLEMENTED: No message received

2 participants