Skip to content

fix(dataconnect): fix deserialization of emulator gRPC error codes into detailed errors#3180

Open
stephenarosaj wants to merge 1 commit into
mainfrom
rosa/emulator-error-fix
Open

fix(dataconnect): fix deserialization of emulator gRPC error codes into detailed errors#3180
stephenarosaj wants to merge 1 commit into
mainfrom
rosa/emulator-error-fix

Conversation

@stephenarosaj

Copy link
Copy Markdown
Contributor

Description

✨ Added gRPC status code mapping to ensure error responses from the local Data Connect emulator are correctly deserialized. Before these changes, when using the emulator, errors are improperly deserialized into unknown-error DataConnectErrors errors instead of ones with detailed code and message fields.

Changes

  • Added GRPC_STATUS_CODE_TO_STRING mapping dictionary
  • Updated toFirebaseError to handle root-level gRPC error responses
  • Added FDC emulator debug log files to .gitignore

Testing

  • Currently, integration tests fail against the emulator. Now they pass.
  • Added unit test verifying deserialization of transcoded gRPC numeric error codes

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

Copy link
Copy Markdown
Contributor

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 adds support for handling gRPC-to-HTTP transcoded error responses in the Data Connect API client by mapping numeric gRPC status codes to their string equivalents. It also updates .gitignore to exclude local debug logs and adds a unit test to verify the new error-handling behavior. A critical issue was identified in the error parsing logic where a null error property in the response could lead to a TypeError and crash the error-handling flow; a code suggestion was provided to safely handle this scenario.


const error: ServerError = (response.data as ErrorResponse).error || {};
const data = response.data as any;
const error: ServerError = (validator.isNonNullObject(data) && 'error' in data) ? data.error : data || {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If the response data contains a null error property (e.g., { "error": null }), validator.isNonNullObject(data) && 'error' in data will evaluate to true. This results in error being assigned null. On the subsequent line, accessing error.status will throw a TypeError: Cannot read properties of null (reading 'status'), crashing the error-handling flow.

To prevent this, ensure that data.error is also a non-null object before assigning it, and fallback to data (if it is a non-null object) or {} otherwise.

Suggested change
const error: ServerError = (validator.isNonNullObject(data) && 'error' in data) ? data.error : data || {};
const error: ServerError = (validator.isNonNullObject(data) && validator.isNonNullObject(data.error)) ? data.error : (validator.isNonNullObject(data) ? data : {});

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.

1 participant