Skip to content

Commit f09ee78

Browse files
committed
update comment
1 parent d0b62cf commit f09ee78

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/internal/middleware/ActivityMiddleware.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,16 @@ public void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exce
7878
throw e;
7979
}
8080

81+
String serializedFailureDetails;
8182
try {
82-
throw new StructuredActivityFailure(
83-
FAILURE_DETAILS_JSON_PRINTER.print(failureDetails.toProto()));
84-
} catch (InvalidProtocolBufferException serializationException) {
83+
serializedFailureDetails = FAILURE_DETAILS_JSON_PRINTER.print(failureDetails.toProto());
84+
} catch (InvalidProtocolBufferException | RuntimeException conversionException) {
8585
LOGGER.log(Level.WARNING,
86-
"Failed to serialize structured failure details; rethrowing the original exception.",
87-
serializationException);
86+
"Failed to convert or serialize structured failure details; rethrowing the original exception.",
87+
conversionException);
8888
throw e;
8989
}
90+
throw new StructuredActivityFailure(serializedFailureDetails);
9091
}
9192
}
9293

azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/internal/middleware/ActivityMiddlewareTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ void rethrowsOriginalWhenProviderThrows() {
206206
assertSame(original, thrown);
207207
}
208208

209+
@Test
210+
@DisplayName("Rethrows the original exception unchanged when failure detail conversion fails")
211+
void rethrowsOriginalWhenFailureDetailConversionFails() {
212+
setProviderSupplier(() -> exception -> {
213+
Map<String, Object> properties = new LinkedHashMap<>();
214+
properties.put(null, "value");
215+
return properties;
216+
});
217+
218+
BusinessException original = new BusinessException("boom");
219+
ActivityMiddleware middleware = new ActivityMiddleware();
220+
221+
Exception thrown = assertThrows(Exception.class,
222+
() -> middleware.invoke(activityContext(), throwingChain(original)));
223+
224+
assertSame(original, thrown);
225+
}
226+
209227
@Test
210228
@DisplayName("Does not invoke the provider for non-activity triggers")
211229
void passesThroughNonActivityTrigger() throws Exception {

0 commit comments

Comments
 (0)