Skip to content

Conversation

@jeet1995
Copy link
Member

@jeet1995 jeet1995 commented Dec 26, 2025

Description

The objective of this PR is to add Owner Resource Not Found (1003) as sub-status code mapping when the owning resource is not found specifically the DocumentCollection resource. The main motivation is disambiguation - is it the child resource not present (such as a document) or its encapsulating resource such as a container. This can help an application developer debug better.

Scenarios tested and fixed

For Direct Mode and Gateway V2 Mode, ensure both container never existed and stale container cache scenarios are appropriately handled.

For Gateway Mode, ensure container never existed scenarios are appropriately handled.

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

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995 jeet1995 changed the title Az cosmos remap sub status for doc requests against non existent container Owner Resource Not Found: Fixes sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995 jeet1995 changed the title Owner Resource Not Found: Fixes sub-status to 1003 for requests to child resources against non-existent container. Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Fixes sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995 jeet1995 marked this pull request as ready for review December 29, 2025 13:32
@jeet1995 jeet1995 requested review from a team and kirankumarkolli as code owners December 29, 2025 13:32
Copilot AI review requested due to automatic review settings December 29, 2025 13:32
@jeet1995 jeet1995 requested a review from a team as a code owner December 29, 2025 13:32
Copy link
Contributor

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

This PR adds sub-status code 1003 (Owner Resource Not Found) for requests to child resources (e.g., documents) when the owning container doesn't exist. The changes ensure proper error reporting across Direct Mode, Gateway V2 Mode, and Gateway Mode connection types.

Key Changes

  • Added error mapping logic to set sub-status code 1003 when container resolution fails during child resource operations
  • Introduced new setSubStatusCode method in CosmosException API via ImplementationBridgeHelpers
  • Added comprehensive test coverage for container not found scenarios across different connection modes

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
QueryPlanRetriever.java Added error mapping to set sub-status 1003 for 404 errors during query plan retrieval
RxCollectionCache.java Added error mapping handlers in collection resolution paths to set sub-status 1003 for child resource operations
StaleResourceRetryPolicy.java Added enclosingOperationTargetResourceType parameter and error mapping logic for retry scenarios
RxDocumentClientImpl.java Updated retry policy instantiation with ResourceType.Document parameter for point operations
ImplementationBridgeHelpers.java Added setSubStatusCode method to CosmosExceptionAccessor interface
CosmosException.java Implemented setSubStatusCode accessor method
CosmosNotFoundTests.java New comprehensive test class covering non-existent and deleted container scenarios
FaultInjectionTestBase.java Enhanced helper methods to support bulk operations and feed range testing
StaleResourceExceptionRetryPolicyTest.java Updated test constructor calls with new null parameter

Comment on lines +95 to +108
}).onErrorMap(throwable -> {
if (throwable instanceof CosmosException) {

CosmosException cosmosException = Utils.as(throwable, CosmosException.class);

if (!ResourceType.DocumentCollection.equals(request.getResourceType()) && com.azure.cosmos.implementation.Exceptions.isNotFound(cosmosException)) {
cosmosExceptionAccessor.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.OWNER_RESOURCE_NOT_EXISTS);
}

return cosmosException;
}

return throwable;
});
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

This error mapping logic is duplicated across multiple locations in this file (lines 95-108, 111-124, and 137-150). Consider extracting this into a private helper method to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@jeet1995 jeet1995 changed the title Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Fixes sub-status to 1003 for requests to child resources against non-existent container. Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Remaps sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

})
.onErrorMap(throwable -> {

if (throwable instanceof CosmosException) {
Copy link
Member

Choose a reason for hiding this comment

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

hmm, not sure this is the place for status code remapping since this is a retry policy - feels this logic should belong to RxCollectionCache only

return cosmosException;
}

if (this.enclosingOperationTargetResourceType != null && !ResourceType.DocumentCollection.equals(this.enclosingOperationTargetResourceType) && Exceptions.isNotFound(cosmosException)) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check sub-status code as well?


CosmosException cosmosException = Utils.as(throwable, CosmosException.class);

if (this.request != null && !ResourceType.DocumentCollection.equals(this.request.getResourceType()) && Exceptions.isNotFound(cosmosException)) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need sub-status code checking?

Mono<DocumentCollection> collectionObs = this.getByNameAsync(metaDataDiagnosticsContext, resourceFullName, request.properties);
return collectionObs.doOnSuccess(collection -> {
return collectionObs.onErrorMap(throwable -> {
return throwable;
Copy link
Member

Choose a reason for hiding this comment

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

revert the change here? there is no remapping of the error cases

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.

2 participants