Skip to content

Commit

Permalink
Fix: do not double-wrap OpenSearchException. (opensearch-project#323)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Jan 17, 2023
1 parent 510f4ef commit 37d4800
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Make ChildrenAggregate as a SingleBucketAggregate ([#306](https://github.com/opensearch-project/opensearch-java/pull/306))
- Fix /_nodes/stats, /_nodes/info throwing serialization error ([#315](https://github.com/opensearch-project/opensearch-java/pull/315))
- Do not double-wrap OpenSearchException on error ([#323](https://github.com/opensearch-project/opensearch-java/pull/323))
- Fix AwsSdk2TransportOptions.responseCompression ([#322](https://github.com/opensearch-project/opensearch-java/pull/322))

### Security
Expand Down
9 changes: 9 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Run Tests](#run-tests)
- [Unit Tests](#unit-tests)
- [Integration Tests](#integration-tests)
- [AWS Transport Integration Tests](#aws-transport-integration-tests)
- [Use an Editor](#use-an-editor)
- [IntelliJ IDEA](#intellij-idea)
- [Visual Studio Code](#visual-studio-code)
Expand Down Expand Up @@ -64,6 +65,14 @@ Run integration tests after starting OpenSearch cluster:
./gradlew clean integrationTest
```

#### AWS Transport Integration Tests

To run integration tests for the AWS transport client, ensure working AWS credentials and specify your OpenSearch domain and region as follows:

```
./gradlew integrationTest -Dtests.awsSdk2support.domainHost=search-...us-west-2.es.amazonaws.com -Dtests.awsSdk2support.domainRegion=us-west-2
```

## Use an Editor

### IntelliJ IDEA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ private <ResponseT, ErrorT> ResponseT parseResponse(
ErrorT error = errorDeserializer.deserialize(parser, mapper);
throw new OpenSearchException((ErrorResponse) error);
}
} catch (OpenSearchException e) {
throw e;
} catch (Exception e) {
// can't parse the error - use a general exception
ErrorCause.Builder cause = new ErrorCause.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import org.opensearch.client.opensearch.OpenSearchAsyncClient;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch._types.OpType;
import org.opensearch.client.opensearch._types.OpenSearchException;
import org.opensearch.client.opensearch._types.Refresh;
import org.opensearch.client.opensearch.core.IndexRequest;
import org.opensearch.client.opensearch.core.IndexResponse;
import org.opensearch.client.opensearch.core.SearchResponse;
import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient;

import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -133,4 +136,18 @@ private CompletableFuture<IndexResponse> addDoc(
return CompletableFuture.failedFuture(e);
}
}

@Test
public void testDoubleWrappedException() throws Exception {
// ensure the test index exists
resetTestIndex(false);
// attempt to create the same index a second time
OpenSearchIndicesClient client = getIndexesClient(false, null, null);
var req = new CreateIndexRequest.Builder().index(TEST_INDEX);
Exception exception = Assert.assertThrows(OpenSearchException.class, () -> {
client.create(req.build());
});
// error message contains the actual error, not a generic [http_exception]
Assert.assertTrue(exception.getMessage().contains("[resource_already_exists_exception]"));
}
}

0 comments on commit 37d4800

Please sign in to comment.