Skip to content

Commit 07ca831

Browse files
committed
Fixups from self-review
1 parent d5e9f88 commit 07ca831

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

temporalio/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def from_failure(
10531053
logger.warning(
10541054
f"Unknown Nexus HandlerErrorType: {nexus_handler_failure_info.type}"
10551055
)
1056-
raise
1056+
_type = nexusrpc.HandlerErrorType.INTERNAL
10571057
retry_behavior = (
10581058
nexusrpc.HandlerErrorRetryBehavior.RETRYABLE
10591059
if (

temporalio/exceptions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,15 @@ def __init__(
375375
operation: str,
376376
operation_token: str,
377377
):
378-
"""Initialize a Nexus operation error."""
378+
"""
379+
Args:
380+
message: The error message.
381+
scheduled_event_id: The NexusOperationScheduled event ID for the failed operation.
382+
endpoint: The endpoint name for the failed operation.
383+
service: The service name for the failed operation.
384+
operation: The name of the failed operation.
385+
operation_token: The operation token returned by the failed operation.
386+
"""
379387
super().__init__(message)
380388
self._scheduled_event_id = scheduled_event_id
381389
self._endpoint = endpoint
@@ -432,7 +440,6 @@ def is_cancelled_exception(exception: BaseException) -> bool:
432440
(
433441
isinstance(exception, ActivityError)
434442
or isinstance(exception, ChildWorkflowError)
435-
# TODO(nexus-preview) test coverage
436443
or isinstance(exception, NexusOperationError)
437444
)
438445
and isinstance(exception.cause, CancelledError)

temporalio/worker/_nexus.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,26 @@ async def _nexus_error_to_nexus_failure_proto(
341341
try:
342342
failure = temporalio.api.failure.v1.Failure()
343343
await self._data_converter.encode_failure(cause, failure)
344-
# TODO(nexus-preview) Note that Java removes the message from the first
345-
# item in the details chain, since in Java's case the nexus exception
346-
# does not have its own message. In the case of Python however, the
347-
# top-level message belongs to the nexus exception itself and so is
348-
# distinct, and it would be reasonable to expect it to be propagated to
349-
# the caller.
344+
# nexusrpc.HandlerError and nexusrpc.OperationError have their
345+
# own error messages and stack traces, independent of any cause
346+
# exception they may have, and it would be reasonable to expect
347+
# these to be propagated to the caller.
348+
#
349+
# In the case of OperationError (UnsuccessfulOperationError
350+
# proto), the server takes the message from the top-level
351+
# UnsuccessfulOperationError and replace the message of the
352+
# first entry in the details chain with it. Presumably the
353+
# server is anticipating that we've hoisted the message to that
354+
# position and is undoing the hoist. Therefore in that case, we
355+
# put the message from the first entry of the details chain at
356+
# the top level and accept that the message of the
357+
# OperationError itself will be lost.
358+
#
359+
# Note that other SDKs (e.g. Java) remove the message from the
360+
# first item in the details chain, since constructors are
361+
# controlled such that the nexus exception itself does not have
362+
# its own message.
350363
#
351-
# In the case of OperationError (UnsuccessfulOperationError proto), the
352-
# server appears to take the message from the top-level
353-
# UnsuccessfulOperationError and replace the message of the first entry
354-
# in the details chain with it. Presumably the server is anticipating
355-
# that we've hoisted the message to that position and is undoing the
356-
# hoist. Therefore in that case, we put the message from the first entry
357-
# of the details chain at the top level and accept that the message of
358-
# the OperationError itself will be lost.
359364
failure_dict = google.protobuf.json_format.MessageToDict(failure)
360365
if isinstance(error, nexusrpc.OperationError):
361366
message = failure_dict.pop("message", str(error))

0 commit comments

Comments
 (0)