Skip to content

Commit

Permalink
handle some netty-specific channel exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet committed May 30, 2024
1 parent a7b6eb0 commit 2ccb4b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Fixed
- ApacheHttpClient5Transport requires Apache Commons Logging dependency ([#1003](https://github.com/opensearch-project/opensearch-java/pull/1003))
- Preserve caller information in stack traces when synchronous callers use asynchronous transports ([#656](https://github.com/opensearch-project/opensearch-java/pull/656))

### Security

Expand Down
9 changes: 5 additions & 4 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ java {
registerFeature("awsSdk2Support") {
usingSourceSet(sourceSets.get("main"))
}

toolchain {
languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion)
vendor = JvmVendorSpec.ADOPTIUM
Expand Down Expand Up @@ -205,6 +205,7 @@ dependencies {
// For AwsSdk2Transport
"awsSdk2SupportCompileOnly"("software.amazon.awssdk","sdk-core","[2.15,3.0)")
"awsSdk2SupportCompileOnly"("software.amazon.awssdk","auth","[2.15,3.0)")
"awsSdk2SupportCompileOnly"("io.netty","netty-handler","4.1.108.Final")
testImplementation("software.amazon.awssdk","sdk-core","[2.15,3.0)")
testImplementation("software.amazon.awssdk","auth","[2.15,3.0)")
testImplementation("software.amazon.awssdk","aws-crt-client","[2.15,3.0)")
Expand Down Expand Up @@ -372,17 +373,17 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.named<JavaCompile>("compileTestJava") {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.named<Test>("integrationTest") {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
}

tasks.named<Test>("unitTest") {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package org.opensearch.client.transport.aws;

import io.netty.channel.ChannelPipelineException;
import io.netty.channel.EventLoopException;
import io.netty.handler.timeout.ReadTimeoutException;
import io.netty.handler.timeout.WriteTimeoutException;
import jakarta.json.JsonObject;
import jakarta.json.stream.JsonParser;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -662,9 +666,6 @@ private static Exception extractAndWrapCause(Exception exception) {
e.initCause(exception);
return e;
}
if (exception instanceof IOException) {
return new IOException(exception.getMessage(), exception);
}
if (exception instanceof OpenSearchException) {
final OpenSearchException e = new OpenSearchException(((OpenSearchException) exception).response());
e.initCause(exception);
Expand All @@ -675,6 +676,29 @@ private static Exception extractAndWrapCause(Exception exception) {
e.initCause(exception);
return e;
}
if (exception instanceof ReadTimeoutException) {
final ReadTimeoutException e = new ReadTimeoutException(exception.getMessage());
e.initCause(exception);
return e;
}
if (exception instanceof WriteTimeoutException) {
final WriteTimeoutException e = new WriteTimeoutException(exception.getMessage());
e.initCause(exception);
return e;
}
if (exception instanceof ChannelPipelineException) {
final ChannelPipelineException e = new ChannelPipelineException(exception.getMessage());
e.initCause(exception);
return e;
}
if (exception instanceof EventLoopException) {
final EventLoopException e = new EventLoopException(exception.getMessage());
e.initCause(exception);
return e;
}
if (exception instanceof IOException) {
return new IOException(exception.getMessage(), exception);
}
if (exception instanceof RuntimeException) {
return new RuntimeException(exception.getMessage(), exception);
}
Expand Down

0 comments on commit 2ccb4b9

Please sign in to comment.