Skip to content

Commit 65a2fb0

Browse files
fix: unwrap thrown exceptions (#10)
1 parent 43a7ded commit 65a2fb0

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

grpc-client-rx-utils/build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ plugins {
77

88
dependencies {
99
api("io.reactivex.rxjava3:rxjava:3.0.6")
10-
api("io.grpc:grpc-stub:1.33.1")
10+
api("io.grpc:grpc-stub:1.35.0")
1111
api(project(":grpc-context-utils"))
12-
implementation("io.grpc:grpc-context:1.33.1")
13-
constraints {
14-
implementation("com.google.guava:guava:30.0-jre") {
15-
because("https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415")
16-
}
17-
}
12+
implementation("io.grpc:grpc-context:1.35.0")
1813

1914
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
2015
testImplementation("org.mockito:mockito-core:3.5.11")

grpc-client-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies {
1313
// End Logging
1414

1515
// grpc
16-
implementation("io.grpc:grpc-core:1.33.1")
16+
implementation("io.grpc:grpc-core:1.35.0")
1717
constraints {
1818
implementation("com.google.guava:guava:30.0-jre") {
1919
because("https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415")

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/GrpcClientRequestContextUtil.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public static <V> V executeWithHeadersContext(@Nonnull Map<String, String> heade
4444
try {
4545
return Context.current().withValue(RequestContext.CURRENT, requestContext).call(c);
4646
} catch (Exception e) {
47+
if (e instanceof RuntimeException) {
48+
throw (RuntimeException)e;
49+
}
4750
throw new RuntimeException(e);
4851
}
4952
}
@@ -58,10 +61,6 @@ public static void executeWithHeadersContext(@Nonnull Map<String, String> header
5861
RequestContext requestContext = new RequestContext();
5962
headers.forEach(requestContext::add);
6063

61-
try {
62-
Context.current().withValue(RequestContext.CURRENT, requestContext).run(r);
63-
} catch (Exception e) {
64-
throw new RuntimeException(e);
65-
}
64+
Context.current().withValue(RequestContext.CURRENT, requestContext).run(r);
6665
}
6766
}

grpc-client-utils/src/test/java/org/hypertrace/core/grpcutils/client/GrpcClientRequestContextUtilTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,18 @@ public void testExecuteWithHeadersContext() {
121121
}
122122

123123
@Test
124-
public void testExecuteWithHeadersContextThrowsRuntimeExceptionWhenRunnableThrowsException() {
124+
public void testExecuteWithHeadersContextRethrowsRuntimeException() {
125+
Map<String, String> headers = Map.of("a1", "v1", "a2", "v2");
126+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
127+
GrpcClientRequestContextUtil.executeWithHeadersContext(headers,
128+
() -> {
129+
throw new IllegalArgumentException("test exception");
130+
});
131+
});
132+
}
133+
134+
@Test
135+
public void testExecuteWithHeadersContextWrapsCheckedException() {
125136
Map<String, String> headers = Map.of("a1", "v1", "a2", "v2");
126137
Assertions.assertThrows(RuntimeException.class, () -> {
127138
GrpcClientRequestContextUtil.executeWithHeadersContext(headers,

grpc-context-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks.test {
1111

1212
dependencies {
1313
// grpc
14-
implementation("io.grpc:grpc-core:1.33.1")
14+
implementation("io.grpc:grpc-core:1.35.0")
1515
constraints {
1616
implementation("com.google.guava:guava:30.0-jre") {
1717
because("https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415")

grpc-server-rx-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
dependencies {
99
api("io.reactivex.rxjava3:rxjava:3.0.6")
10-
api("io.grpc:grpc-stub:1.33.1")
10+
api("io.grpc:grpc-stub:1.35.0")
1111
constraints {
1212
implementation("com.google.guava:guava:30.0-jre") {
1313
because("https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415")

grpc-server-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies {
1717
// End Logging
1818

1919
// grpc
20-
implementation("io.grpc:grpc-core:1.33.1")
20+
implementation("io.grpc:grpc-core:1.35.0")
2121
constraints {
2222
implementation("com.google.guava:guava:30.0-jre") {
2323
because("https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415")

0 commit comments

Comments
 (0)