opensearch-project / opensearch-project/opensearch-java
[BUG] Inconsistent use for 409 exceptions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 165
- Forks
- 250
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 26
Description
What is the bug?
Depending on what transport is being used, different exceptions are thrown.
If I setup my client like this:
SdkHttpClient httpClient = ApacheHttpClient.builder()
.maxConnections(100)
.connectionTimeout(Duration.ofSeconds(10))
.build();
var transport = AwsSdk2Transport(httpClient,
host, "es", Region.EU_WEST_1,
AwsSdk2TransportOptions.builder().build());
var os = new OpenSearchClient(transport);
And do an index request (to insert a duplicate):
os.index(indexRequest)
It turns into a 409 conflict in a OpenSearchException.
But if I configure my client like this with another transport:
var transport = ApacheHttpClient5TransportBuilder
.builder(org.apache.hc.core5.http.HttpHost.create(host))
.build();
var os = new OpenSearchClient(transport);
And run the same code with the index request I get org.opensearch.client.transport.httpclient5.ResponseException instead.
We use both transports, one when running in production on AWS and the other one when testing locally.
This means that I need to have two different catch clauses to handle the same error, but even worse is that this behavior means that I can't test the production code locally as the behavior will change when I deploy to AWS compared to running locally or on CI.
Somewhat related to https://github.com/opensearch-project/opensearch-java/issues/749 but I consider this a bug and not a feature request, especially since this makes it very hard to test my code and prepare for production.
(Using RestClientTransport(RestClient.builder(...)) seems to throw org.opensearch.client.ResponseException which is a third distinct exception for the same problem so a third catch clause would be required - but that seems deprecated anyway.)
How can one reproduce the bug?
See above.
What is the expected behavior?
The same exception should always be thrown independently of which transport is being used, or at least if they need to be different then they should both extend a common exception so I only need one catch clause and not two.
What is your host/environment?
Reproduced on Mac / Linux.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the duplicate index request with AwsSdk2Transport and ApacheHttpClient5TransportBuilder, then compare the exceptions raised by each transport. Trace the transport exception paths and verify that the same exception, or a shared common exception, is exposed for the 409 response; add coverage for both configurations and the expected catch behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100