Skip to content

Commit b4e737e

Browse files
More logging on jackson ser/de (#279)
1 parent cca0f96 commit b4e737e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

sdk-api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ dependencies {
1010

1111
api(project(":sdk-common"))
1212

13+
implementation(coreLibs.log4j.api)
14+
1315
testImplementation(project(":sdk-core"))
1416
testImplementation(testingLibs.junit.jupiter)
1517
testImplementation(testingLibs.assertj)

sdk-api/src/main/java/dev/restate/sdk/Component.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.util.concurrent.Executors;
1818
import java.util.function.BiFunction;
1919
import java.util.stream.Collectors;
20+
import org.apache.logging.log4j.LogManager;
21+
import org.apache.logging.log4j.Logger;
2022

2123
public final class Component implements BindableComponent<Component.Options> {
2224
private final ComponentDefinition<Component.Options> componentDefinition;
@@ -102,6 +104,8 @@ public static class Handler<REQ, RES> implements InvocationHandler<Component.Opt
102104
private final HandlerSignature<REQ, RES> handlerSignature;
103105
private final BiFunction<Context, REQ, RES> runner;
104106

107+
private static final Logger LOG = LogManager.getLogger(Handler.class);
108+
105109
public Handler(
106110
HandlerSignature<REQ, RES> handlerSignature,
107111
BiFunction<? extends Context, REQ, RES> runner) {
@@ -152,6 +156,7 @@ public void handle(
152156
} catch (Error e) {
153157
throw e;
154158
} catch (Throwable e) {
159+
LOG.warn("Cannot deserialize input", e);
155160
callback.onCancel(
156161
new TerminalException(
157162
TerminalException.BAD_REQUEST_CODE,
@@ -177,6 +182,7 @@ public void handle(
177182
} catch (Error e) {
178183
throw e;
179184
} catch (Throwable e) {
185+
LOG.warn("Cannot serialize output", e);
180186
callback.onCancel(
181187
new TerminalException(
182188
TerminalException.INTERNAL_SERVER_ERROR_CODE,

sdk-serde-jackson/src/main/java/dev/restate/sdk/serde/jackson/JacksonSerdes.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public byte[] serialize(@Nullable T value) {
6161
try {
6262
return mapper.writeValueAsBytes(value);
6363
} catch (JsonProcessingException e) {
64-
throw new RuntimeException("Cannot serialize value", e);
64+
sneakyThrow(e);
65+
return null;
6566
}
6667
}
6768

@@ -70,7 +71,8 @@ public T deserialize(byte[] value) {
7071
try {
7172
return mapper.readValue(value, clazz);
7273
} catch (IOException e) {
73-
throw new RuntimeException("Cannot deserialize value", e);
74+
sneakyThrow(e);
75+
return null;
7476
}
7577
}
7678

@@ -94,7 +96,8 @@ public byte[] serialize(@Nullable T value) {
9496
try {
9597
return mapper.writeValueAsBytes(value);
9698
} catch (JsonProcessingException e) {
97-
throw new RuntimeException("Cannot serialize value", e);
99+
sneakyThrow(e);
100+
return null;
98101
}
99102
}
100103

@@ -103,7 +106,8 @@ public T deserialize(byte[] value) {
103106
try {
104107
return mapper.readValue(value, typeReference);
105108
} catch (IOException e) {
106-
throw new RuntimeException("Cannot deserialize value", e);
109+
sneakyThrow(e);
110+
return null;
107111
}
108112
}
109113

@@ -113,4 +117,9 @@ public String contentType() {
113117
}
114118
};
115119
}
120+
121+
@SuppressWarnings("unchecked")
122+
private static <E extends Throwable> void sneakyThrow(Object exception) throws E {
123+
throw (E) exception;
124+
}
116125
}

0 commit comments

Comments
 (0)