Skip to content

Conversation

jeet1995
Copy link
Member

@jeet1995 jeet1995 commented Oct 18, 2025

Description

This pull request wraps JSON parsing exceptions as a CosmosException with the JSON parsing exception as an inner exception.

Documentation updates:

  • The status codes documentation (StatusCodes.md) is updated to include sub-status code 21011 for client-generated internal server errors related to JSON parsing failures, clarifying the error's meaning and expected behavior.

Test infrastructure improvements:

  • Added a new test class MalformedResponseTests.java to validate that malformed server responses result in a correctly wrapped CosmosException, using reflection to inject a failing ObjectMapper.

** An example of malformed document being logged **

2025-10-17 22:59:14,221       [reactor-http-nio-1] ERROR com.azure.cosmos.implementation.directconnectivity.JsonNodeStorePayload - Failed to parse JSON document even after applying fallback charset decoder. Document in Base64 format: [eyJBZGRyZXNzcyI6W3siaXNQcmltYXJ5Ijp0cnVlLCJwaHlzY2lhbFVyaSI6InJudGJkOi8vY2RiLW1zLXByb2QtY2VudHJhbHVzMS1iZTQ2LmRvY3VtZW50cy5henVyZS5jb206MTQwMjgvYXBwcy83ZTQzOWIxYi02YjZkLTQxMjYtOGRkNC1kMDJkNzhhMWY2YTEvc2VydmljZXMvMGMzNmZhZDUtZWI2Yi00NDkxLWI5NTgtNWVjMmUyMTdiYjQwL3BhcnRpdGlvbnMvNjA3OTVjMzMtMmVhNi00ZWRiLWJjMDgtZmY5Y2I0NDJiNDFkL3JlcGxpY2FzLzEzNDA1MjI4ODE0OTgyMzQyNXAvIiwiaXNBdXhpbGlhcnkiOmZhbHNlLCJfcmlkIjoiSE9RZkFPQy1LUkE9IiwicHJvdG9jb2wiOiJybnRiZCIsInBhcnRpdGlvbktleVJhbmdlSWQiOiIwIiwicGFydGl0aW9uSW5kZXgiOiIyMDkwMDEyQDI3MTE3MTU1MiJ9LHsiaXNQcmltYXJ5IjpmYWxzZSwicGh5c2NpYWxVcmkiOiJybnRiZDovL2NkYi1tcy1wcm9kLWNlbnRyYWx1czEtYmU0Ni5kb2N1bWVudHMuYXp1cmUuY29tOjE0MDQzL2FwcHMvN2U0MzliMWItNmI2ZC00MTI2LThkZDQtZDAyZDc4YTFmNmExL3NlcnZpY2VzLzBjMzZmYWQ1LWViNmItNDQ5MS1iOTU4LTVlYzJlMjE3YmI0MC9wYXJ0aXRpb25zLzYwNzk1YzMzLTJlYTYtNGVkYi1iYzA4LWZmOWNiNDQyYjQxZC9yZXBsaWNhcy8xMzQwNTIyODgxNDk4MjM0MjRzLyIsImlzQXV4aWxpYXJ5IjpmYWxzZSwiX3JpZCI6IkhPUWZBT0MtS1JBPSIsInByb3RvY29sIjoicm50YmQiLCJwYXJ0aXRpb25LZXlSYW5nZUlkIjoiMCIsInBhcnRpdGlvbkluZGV4IjoiMjA5MDAxMkAyNzExNzE1NTIifSx7ImlzUHJpbWFyeSI6ZmFsc2UsInBoeXNjaWFsVXJpIjoicm50YmQ6Ly9jZGItbXMtcHJvZC1jZW50cmFsdXMxLWJlNDYuZG9jdW1lbnRzLmF6dXJlLmNvbToxNDM3NS9hcHBzLzdlNDM5YjFiLTZiNmQtNDEyNi04ZGQ0LWQwMmQ3OGExZjZhMS9zZXJ2aWNlcy8wYzM2ZmFkNS1lYjZiLTQ0OTEtYjk1OC01ZWMyZTIxN2JiNDAvcGFydGl0aW9ucy82MDc5NWMzMy0yZWE2LTRlZGItYmMwOC1mZjljYjQ0MmI0MWQvcmVwbGljYXMvMTM0MDUyMjg4MTQ5ODIzNDIzcy8iLCJpc0F1eGlsaWFyeSI6ZmFsc2UsIl9yaWQiOiJIT1FmQU9DLUtSQT0iLCJwcm90b2NvbCI6InJudGJkIiwicGFydGl0aW9uS2V5UmFuZ2VJZCI6IjAiLCJwYXJ0aXRpb25JbmRleCI6IjIwOTAwMTJAMjcxMTcxNTUyIn1dLCJfY291bnQiOjN9]
com.fasterxml.jackson.core.JsonParseException: Simulated failure
	at com.azure.cosmos.implementation.MalformedResponseTests$FailingObjectMapper.readTree(MalformedResponseTests.java:106) ~[test-classes/:?]
	at com.azure.cosmos.implementation.directconnectivity.JsonNodeStorePayload.fromJsonWithFallbackCharsetDecoder(JsonNodeStorePayload.java:73) ~[classes/:?]
	at com.azure.cosmos.implementation.directconnectivity.JsonNodeStorePayload.fromJson(JsonNodeStorePayload.java:47) ~[classes/:?]

Configuration options:

  • Introduces a JVM Config - COSMOS.IS_NON_PARSEABLE_DOCUMENT_LOGGING_ENABLED and environment variable COSMOS_IS_NON_PARSEABLE_DOCUMENT_LOGGING_ENABLED which can be set to true or false which when set to true emits as a log line the non-parseable document in Base64-encoded format.

All SDK Contribution checklist:

  • [] The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@jeet1995 jeet1995 requested review from a team and kirankumarkolli as code owners October 18, 2025 00:42
@Copilot Copilot AI review requested due to automatic review settings October 18, 2025 00:42
Copy link
Contributor

@Copilot Copilot AI left a 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).

…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
@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@jeet1995
Copy link
Member Author

/azp run java - cosmos - kafka

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

/azp run java - cosmos - kafka

@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

/azp run java - cosmos - spark

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@jeet1995
Copy link
Member Author

/azp run java - cosmos - spark

@jeet1995
Copy link
Member Author

/azp run java - cosmos - kafka

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

2 similar comments
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant