Skip to content

Commit 76672fa

Browse files
Fix ApplicationFailure.Builder handling a null Category (#2602)
Fix ApplicationFailure.Builder handling a null Category
1 parent ffb44f9 commit 76672fa

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

temporal-sdk/src/main/java/io/temporal/failure/ApplicationFailure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public ApplicationFailure build() {
341341
details == null ? new EncodedValues(null) : details,
342342
cause,
343343
nextRetryDelay,
344-
category);
344+
category == null ? ApplicationErrorCategory.UNSPECIFIED : category);
345345
}
346346
}
347347
}

temporal-sdk/src/main/java/io/temporal/failure/DefaultFailureConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,17 @@ private Failure exceptionToFailure(Throwable throwable) {
244244
ApplicationFailureInfo.Builder info =
245245
ApplicationFailureInfo.newBuilder()
246246
.setType(ae.getType())
247-
.setNonRetryable(ae.isNonRetryable())
248-
.setCategory(FailureUtils.categoryToProto(ae.getCategory()));
247+
.setNonRetryable(ae.isNonRetryable());
249248
Optional<Payloads> details = ((EncodedValues) ae.getDetails()).toPayloads();
250249
if (details.isPresent()) {
251250
info.setDetails(details.get());
252251
}
253252
if (ae.getNextRetryDelay() != null) {
254253
info.setNextRetryDelay(ProtobufTimeUtils.toProtoDuration(ae.getNextRetryDelay()));
255254
}
255+
if (ae.getCategory() != null) {
256+
info.setCategory(FailureUtils.categoryToProto(ae.getCategory()));
257+
}
256258
failure.setApplicationFailureInfo(info);
257259
} else if (throwable instanceof TimeoutFailure) {
258260
TimeoutFailure te = (TimeoutFailure) throwable;

temporal-sdk/src/test/java/io/temporal/internal/worker/ActivityFailedMetricsTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public static class TestActivityImpl implements TestActivity {
8989
@Override
9090
public void execute(boolean isBenign) {
9191
if (!isBenign) {
92-
throw ApplicationFailure.newFailure("Non-benign activity failure", "NonBenignType");
92+
throw ApplicationFailure.newBuilder()
93+
.setMessage("Non-benign activity failure")
94+
.setType("NonBenignType")
95+
.build();
9396
} else {
9497
throw ApplicationFailure.newBuilder()
9598
.setMessage("Benign activity failure")

0 commit comments

Comments
 (0)