Skip to content

feat(data-connect): introduce error handling for streaming#9726

Merged
stephenarosaj merged 35 commits intopasta/mainfrom
pasta/orzo
Mar 18, 2026
Merged

feat(data-connect): introduce error handling for streaming#9726
stephenarosaj merged 35 commits intopasta/mainfrom
pasta/orzo

Conversation

@stephenarosaj
Copy link
Copy Markdown
Contributor

@stephenarosaj stephenarosaj commented Mar 16, 2026

Description

✨ This PR introduces error handling for the streaming transport layer. It ensures that local and server-side errors are handled correctly, mirroring the existing behavior of the REST architecture while supporting the unique lifecycles required for subscriptions.

Changes

  • Execution Errors: Updated the response handler to dynamically construct a failure response and reject execution promises with a typed DataConnectOperationError when an error payload is received from the server for queries or mutations.
  • Message Send Failures: Added error catching logic to send*Message() to gracefully reject the associated execution promise if the local message transmission fails.
  • Subscription Errors: Ensured that local transmission failures for subscriptions synthesize a mock response containing the error and pass it to the subscription's notification hook, allowing the Query layer to handle and broadcast the error. Server responses for subscriptions containing errors are correctly routed to hooks without spontaneously terminating the tracked stream.
  • Tracking + Cleanup Refactorization: Consolidated request tracking and cleanup logic and now use promise callbacks to cleanup.

Testing

  • Extended stream transport unit tests to verify that execution promises gracefully reject with a DataConnectOperationError upon receiving error payloads from the server.
  • Added tests verifying that if a local message transmission fails for executions, the associated tracking maps are properly cleaned up.
  • Added tests to ensure subscribe operations correctly call the notification hook with an error payload and successfully tear down tracking logic if the initial transmission fails.
  • Confirmed that error responses for active subscriptions continue to be routed to the target hooks instead of throwing exceptions or prematurely cleaning the map.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 16, 2026

⚠️ No Changeset found

Latest commit: 4c4c002

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@stephenarosaj stephenarosaj changed the base branch from main to pasta/main March 16, 2026 22:03
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces robust error handling for streaming transport responses. The changes ensure that errors in queries and mutations reject the corresponding promises and that state is cleaned up correctly. For subscriptions, errors are now routed to the subscription hook without terminating the subscription, which is the correct behavior. The implementation is solid, and the new unit tests provide excellent coverage for the new error handling logic. I have one suggestion to improve maintainability by reducing code duplication.

Comment thread packages/data-connect/src/network/stream/streamTransport.ts
@firebase firebase deleted a comment from gemini-code-assist Bot Mar 16, 2026
@stephenarosaj
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive error handling for the streaming transport layer. The changes are well-structured, with significant refactoring to improve code clarity by centralizing request tracking and cleanup logic. Promises for queries and mutations are now correctly rejected on errors, while subscriptions properly receive error payloads without terminating. The addition of thorough unit tests covering all new error paths is also a great improvement. I have one suggestion to remove a redundant line of code to further centralize the cleanup logic.

Comment thread packages/data-connect/src/network/stream/streamTransport.ts Outdated
@stephenarosaj stephenarosaj marked this pull request as ready for review March 17, 2026 20:52
@stephenarosaj stephenarosaj merged commit 620f004 into pasta/main Mar 18, 2026
29 checks passed
@stephenarosaj stephenarosaj deleted the pasta/orzo branch March 18, 2026 14:51
@firebase firebase locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants