Skip to content

Commit 6d50161

Browse files
Respond to PR comments
1 parent 9545fd2 commit 6d50161

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

temporal-sdk/src/main/java/io/temporal/internal/common/InternalUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public static NexusWorkflowStarter createNexusBoundStub(
8686
} catch (JsonProcessingException e) {
8787
// Not expected as the link is constructed by the SDK.
8888
throw new HandlerException(
89-
HandlerException.ErrorType.BAD_REQUEST,
90-
new IllegalArgumentException("failed to generate workflow operation token", e));
89+
HandlerException.ErrorType.BAD_REQUEST, "failed to generate workflow operation token", e);
9190
}
9291
List<Link> links =
9392
request.getLinks() == null

temporal-sdk/src/main/java/io/temporal/internal/common/NexusUtil.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public static Failure temporalFailureToNexusFailure(
6060
io.temporal.api.failure.v1.Failure temporalFailure) {
6161
String details;
6262
try {
63-
details = PROTO_JSON_PRINTER.print(temporalFailure.toBuilder().setMessage("").build());
63+
details =
64+
PROTO_JSON_PRINTER.print(
65+
temporalFailure.toBuilder().setMessage("").setStackTrace("").build());
6466
} catch (InvalidProtocolBufferException e) {
6567
return Failure.newBuilder()
6668
.setMessage("Failed to serialize failure details")
@@ -138,7 +140,9 @@ public static FailureInfo temporalFailureToNexusFailureInfo(
138140
io.temporal.api.failure.v1.Failure temporalFailure) {
139141
String details;
140142
try {
141-
details = PROTO_JSON_PRINTER.print(temporalFailure.toBuilder().setMessage("").build());
143+
details =
144+
PROTO_JSON_PRINTER.print(
145+
temporalFailure.toBuilder().setMessage("").setStackTrace("").build());
142146
} catch (InvalidProtocolBufferException e) {
143147
return FailureInfo.newBuilder()
144148
.setMessage("Failed to serialize failure details")
@@ -157,18 +161,23 @@ public static Failure exceptionToNexusFailure(Throwable exception, DataConverter
157161
return temporalFailureToNexusFailure(failure);
158162
}
159163

164+
/**
165+
* Convert a HandlerException to the legacy HandlerError format used by Nexus, including
166+
* converting the cause to a Failure.
167+
*/
160168
public static HandlerError handlerErrorToNexusError(
161169
HandlerException e, DataConverter dataConverter) {
162170
HandlerError.Builder handlerError =
163171
HandlerError.newBuilder()
164172
.setErrorType(e.getErrorType().toString())
165173
.setRetryBehavior(mapRetryBehavior(e.getRetryBehavior()));
166-
// TODO: check if this works on old server
167174
if (e.getCause() != null) {
168175
handlerError.setFailure(exceptionToNexusFailure(e.getCause(), dataConverter));
169176
} else if (e.getMessage() != null && !e.getMessage().isEmpty()) {
170-
// Include message even when there's no cause
171-
handlerError.setFailure(Failure.newBuilder().setMessage(e.getMessage()).build());
177+
// Generate a failure from the message if no cause is provided, to ensure the error is not
178+
// empty
179+
handlerError.setFailure(
180+
exceptionToNexusFailure(new RuntimeException(e.getMessage()), dataConverter));
172181
}
173182
return handlerError.build();
174183
}

temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusTaskHandlerImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public Result handle(NexusTask task, Scope metricsScope) throws TimeoutException
105105
java.util.concurrent.TimeUnit.MILLISECONDS);
106106
} catch (IllegalArgumentException e) {
107107
throw new HandlerException(
108-
HandlerException.ErrorType.BAD_REQUEST,
109-
new RuntimeException("Invalid request timeout header", e));
108+
HandlerException.ErrorType.BAD_REQUEST, "Invalid request timeout header", e);
110109
}
111110
}
112111

@@ -125,12 +124,14 @@ public Result handle(NexusTask task, Scope metricsScope) throws TimeoutException
125124
default:
126125
throw new HandlerException(
127126
HandlerException.ErrorType.NOT_IMPLEMENTED,
128-
new RuntimeException("Unknown request type: " + request.getVariantCase()));
127+
"Unknown request type: " + request.getVariantCase(),
128+
(Throwable) null);
129129
}
130130
} catch (HandlerException e) {
131131
return new Result(e);
132132
} catch (Throwable e) {
133-
return new Result(new HandlerException(HandlerException.ErrorType.INTERNAL, e));
133+
return new Result(
134+
new HandlerException(HandlerException.ErrorType.INTERNAL, "internal handler error", e));
134135
} finally {
135136
// If the task timed out, we should not send a response back to the server
136137
if (timedOut.get()) {
@@ -285,7 +286,8 @@ private StartOperationResponse handleStartOperation(
285286
log.error("failed to parse link url: " + link.getUrl(), e);
286287
throw new HandlerException(
287288
HandlerException.ErrorType.BAD_REQUEST,
288-
new RuntimeException("Invalid link URL: " + link.getUrl(), e));
289+
"Invalid link URL: " + link.getUrl(),
290+
e);
289291
}
290292
});
291293

temporal-sdk/src/main/java/io/temporal/nexus/WorkflowRunOperationImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public OperationStartResult<R> start(
6868
ctx.addLinks(nexusProtoLinkToLink(nexusLink));
6969
} catch (URISyntaxException e) {
7070
// Not expected as the link is constructed by the SDK.
71-
throw new HandlerException(
72-
HandlerException.ErrorType.INTERNAL,
73-
new IllegalArgumentException("failed to parse URI", e));
71+
throw new HandlerException(HandlerException.ErrorType.INTERNAL, "failed to parse URI", e);
7472
}
7573
}
7674
return result.build();
@@ -86,8 +84,7 @@ public void cancel(
8684
operationCancelDetails.getOperationToken());
8785
} catch (IllegalArgumentException e) {
8886
throw new HandlerException(
89-
HandlerException.ErrorType.BAD_REQUEST,
90-
new IllegalArgumentException("failed to parse operation token", e));
87+
HandlerException.ErrorType.BAD_REQUEST, "failed to parse operation token", e);
9188
}
9289

9390
WorkflowClient client = CurrentNexusOperationContext.get().getWorkflowClient();

0 commit comments

Comments
 (0)