-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Wrap JSON Parsing Errors as CosmosException
.
#47040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improve handling of malformed/non-parseable JSON responses by wrapping parsing failures in CosmosException with a new substatus code and optional payload logging.
- Introduces FAILED_TO_PARSE_SERVER_RESPONSE substatus and a centralized Utils.createCosmosException factory.
- Enhances JsonNodeStorePayload to emit richer diagnostics and optionally log Base64-encoded raw payload when parsing fails.
- Adds (but currently ignores) tests for malformed responses and updates existing tests for new constructor signature.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
StoreResponse.java | Passes response headers into JsonNodeStorePayload to enable richer CosmosException creation. |
JsonNodeStorePayload.java | Adds error wrapping, optional Base64 logging, and new constructor accepting response headers. |
Utils.java | Adds helper to construct CosmosException with status/substatus and headers. |
RxGatewayStoreModel.java | Adjusts logging format for unexpected failures; minor refactor around statusCode initialization. |
HttpConstants.java | Adds new substatus code for failed server response parsing. |
Configs.java | Adds configuration toggle for logging non-parseable payloads. |
JsonNodeStorePayloadTests.java | Updates test to use new constructor signature with headers placeholder. |
MalformedResponseTests.java | Adds reflective test to force deserialization failures (currently ignored). |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Utils.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Utils.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java
Show resolved
Hide resolved
...azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/MalformedResponseTests.java
Show resolved
Hide resolved
...azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/MalformedResponseTests.java
Outdated
Show resolved
Hide resolved
...s/src/main/java/com/azure/cosmos/implementation/directconnectivity/JsonNodeStorePayload.java
Show resolved
Hide resolved
...s/src/main/java/com/azure/cosmos/implementation/directconnectivity/JsonNodeStorePayload.java
Outdated
Show resolved
Hide resolved
…pParsingErrorLoggingChanges # Conflicts: # sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java # sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/JsonNodeStorePayload.java
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - cosmos - tests |
/azp run java - cosmos - kafka |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - cosmos - kafka |
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - cosmos - spark |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - cosmos - tests |
/azp run java - cosmos - spark |
/azp run java - cosmos - kafka |
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
Azure Pipelines successfully started running 1 pipeline(s). |
Azure Pipelines successfully started running 1 pipeline(s). |
Description
This pull request wraps JSON parsing exceptions as a
CosmosException
with the JSON parsing exception as an inner exception.Documentation updates:
StatusCodes.md
) is updated to include sub-status code21011
for client-generated internal server errors related to JSON parsing failures, clarifying the error's meaning and expected behavior.Test infrastructure improvements:
MalformedResponseTests.java
to validate that malformed server responses result in a correctly wrappedCosmosException
, using reflection to inject a failingObjectMapper
.** An example of malformed document being logged **
Configuration options:
COSMOS.IS_NON_PARSEABLE_DOCUMENT_LOGGING_ENABLED
and environment variableCOSMOS_IS_NON_PARSEABLE_DOCUMENT_LOGGING_ENABLED
which can be set totrue
orfalse
which when set totrue
emits as a log line the non-parseable document in Base64-encoded format.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines