Skip to content

Commit 8b153e1

Browse files
committed
Don't pass cause to HandlerError constructor
1 parent a547276 commit 8b153e1

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

temporalio/nexus/_operation_handlers.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ async def fetch_result(
112112
# "Failed to decode operation token as workflow operation token. "
113113
# "Fetching result for non-workflow operations is not supported.",
114114
# type=HandlerErrorType.NOT_FOUND,
115-
# cause=err,
116-
# )
115+
# ) from err
117116
# ctx = _temporal_fetch_operation_context.get()
118117
# try:
119118
# client_handle = nexus_handle.to_workflow_handle(
@@ -123,8 +122,7 @@ async def fetch_result(
123122
# raise HandlerError(
124123
# "Failed to construct workflow handle from workflow operation token",
125124
# type=HandlerErrorType.NOT_FOUND,
126-
# cause=err,
127-
# )
125+
# ) from err
128126
# return await client_handle.result()
129127

130128

@@ -145,8 +143,7 @@ async def cancel_operation(
145143
"Failed to decode operation token as workflow operation token. "
146144
"Canceling non-workflow operations is not supported.",
147145
type=HandlerErrorType.NOT_FOUND,
148-
cause=err,
149-
)
146+
) from err
150147

151148
ctx = _temporal_cancel_operation_context.get()
152149
try:
@@ -157,6 +154,5 @@ async def cancel_operation(
157154
raise HandlerError(
158155
"Failed to construct workflow handle from workflow operation token",
159156
type=HandlerErrorType.NOT_FOUND,
160-
cause=err,
161-
)
157+
) from err
162158
await client_workflow_handle.cancel(**kwargs)

temporalio/worker/_nexus.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ async def deserialize(
381381
raise nexusrpc.HandlerError(
382382
"Data converter failed to decode Nexus operation input",
383383
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
384-
cause=err,
385384
retryable=False,
386385
) from err
387386

@@ -393,36 +392,32 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
393392
if isinstance(err, nexusrpc.HandlerError):
394393
return err
395394
elif isinstance(err, ApplicationError):
396-
return nexusrpc.HandlerError(
395+
handler_err = nexusrpc.HandlerError(
397396
# TODO(nexus-prerelease): what should message be?
398397
err.message,
399398
type=nexusrpc.HandlerErrorType.INTERNAL,
400-
cause=err,
401399
retryable=not err.non_retryable,
402400
)
403401
elif isinstance(err, RPCError):
404402
if err.status == RPCStatusCode.INVALID_ARGUMENT:
405-
return nexusrpc.HandlerError(
403+
handler_err = nexusrpc.HandlerError(
406404
err.message,
407405
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
408-
cause=err,
409406
)
410407
elif err.status in [
411408
RPCStatusCode.ALREADY_EXISTS,
412409
RPCStatusCode.FAILED_PRECONDITION,
413410
RPCStatusCode.OUT_OF_RANGE,
414411
]:
415-
return nexusrpc.HandlerError(
412+
handler_err = nexusrpc.HandlerError(
416413
err.message,
417414
type=nexusrpc.HandlerErrorType.INTERNAL,
418-
cause=err,
419415
retryable=False,
420416
)
421417
elif err.status in [RPCStatusCode.ABORTED, RPCStatusCode.UNAVAILABLE]:
422-
return nexusrpc.HandlerError(
418+
handler_err = nexusrpc.HandlerError(
423419
err.message,
424420
type=nexusrpc.HandlerErrorType.UNAVAILABLE,
425-
cause=err,
426421
)
427422
elif err.status in [
428423
RPCStatusCode.CANCELLED,
@@ -436,37 +431,36 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
436431
# we convert to internal because this is not a client auth error and happens
437432
# when the handler fails to auth with Temporal and should be considered
438433
# retryable.
439-
return nexusrpc.HandlerError(
440-
err.message, type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
434+
handler_err = nexusrpc.HandlerError(
435+
err.message, type=nexusrpc.HandlerErrorType.INTERNAL
441436
)
442437
elif err.status == RPCStatusCode.NOT_FOUND:
443-
return nexusrpc.HandlerError(
444-
err.message, type=nexusrpc.HandlerErrorType.NOT_FOUND, cause=err
438+
handler_err = nexusrpc.HandlerError(
439+
err.message, type=nexusrpc.HandlerErrorType.NOT_FOUND
445440
)
446441
elif err.status == RPCStatusCode.RESOURCE_EXHAUSTED:
447-
return nexusrpc.HandlerError(
442+
handler_err = nexusrpc.HandlerError(
448443
err.message,
449444
type=nexusrpc.HandlerErrorType.RESOURCE_EXHAUSTED,
450-
cause=err,
451445
)
452446
elif err.status == RPCStatusCode.UNIMPLEMENTED:
453-
return nexusrpc.HandlerError(
447+
handler_err = nexusrpc.HandlerError(
454448
err.message,
455449
type=nexusrpc.HandlerErrorType.NOT_IMPLEMENTED,
456-
cause=err,
457450
)
458451
elif err.status == RPCStatusCode.DEADLINE_EXCEEDED:
459-
return nexusrpc.HandlerError(
452+
handler_err = nexusrpc.HandlerError(
460453
err.message,
461454
type=nexusrpc.HandlerErrorType.UPSTREAM_TIMEOUT,
462-
cause=err,
463455
)
464456
else:
465-
return nexusrpc.HandlerError(
457+
handler_err = nexusrpc.HandlerError(
466458
f"Unhandled RPC error status: {err.status}",
467459
type=nexusrpc.HandlerErrorType.INTERNAL,
468-
cause=err,
469460
)
470-
return nexusrpc.HandlerError(
471-
str(err), type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
472-
)
461+
else:
462+
handler_err = nexusrpc.HandlerError(
463+
str(err), type=nexusrpc.HandlerErrorType.INTERNAL
464+
)
465+
handler_err.__cause__ = err
466+
return handler_err

tests/nexus/test_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ async def handler_error_internal(
194194
message="deliberate internal handler error",
195195
type=HandlerErrorType.INTERNAL,
196196
retryable=False,
197-
cause=RuntimeError("cause message"),
198-
)
197+
) from RuntimeError("cause message")
199198

200199
@sync_operation
201200
async def operation_error_failed(

0 commit comments

Comments
 (0)