Skip to content

Commit 3b92183

Browse files
committed
RTU: Move HandlerError to root module
1 parent 8b3af4d commit 3b92183

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

temporalio/nexus/_operation_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
)
1010

1111
from nexusrpc import (
12+
HandlerError,
13+
HandlerErrorType,
1214
InputT,
1315
OperationInfo,
1416
OutputT,
@@ -17,8 +19,6 @@
1719
CancelOperationContext,
1820
FetchOperationInfoContext,
1921
FetchOperationResultContext,
20-
HandlerError,
21-
HandlerErrorType,
2222
OperationHandler,
2323
StartOperationContext,
2424
StartOperationResultAsync,

temporalio/worker/_nexus.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ async def _operation_error_to_proto(
343343
)
344344

345345
async def _handler_error_to_proto(
346-
self, err: nexusrpc.handler.HandlerError
346+
self, err: nexusrpc.HandlerError
347347
) -> temporalio.api.nexus.v1.HandlerError:
348348
return temporalio.api.nexus.v1.HandlerError(
349349
error_type=err.type.value,
@@ -378,50 +378,50 @@ async def deserialize(
378378
)
379379
return input
380380
except Exception as err:
381-
raise nexusrpc.handler.HandlerError(
381+
raise nexusrpc.HandlerError(
382382
"Data converter failed to decode Nexus operation input",
383-
type=nexusrpc.handler.HandlerErrorType.BAD_REQUEST,
383+
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
384384
cause=err,
385385
retryable=False,
386386
) from err
387387

388388

389389
# TODO(nexus-prerelease): tests for this function
390-
def _exception_to_handler_error(err: BaseException) -> nexusrpc.handler.HandlerError:
390+
def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
391391
# Based on sdk-typescript's convertKnownErrors:
392392
# https://github.com/temporalio/sdk-typescript/blob/nexus/packages/worker/src/nexus.ts
393-
if isinstance(err, nexusrpc.handler.HandlerError):
393+
if isinstance(err, nexusrpc.HandlerError):
394394
return err
395395
elif isinstance(err, ApplicationError):
396-
return nexusrpc.handler.HandlerError(
396+
return nexusrpc.HandlerError(
397397
# TODO(nexus-prerelease): what should message be?
398398
err.message,
399-
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
399+
type=nexusrpc.HandlerErrorType.INTERNAL,
400400
cause=err,
401401
retryable=not err.non_retryable,
402402
)
403403
elif isinstance(err, RPCError):
404404
if err.status == RPCStatusCode.INVALID_ARGUMENT:
405-
return nexusrpc.handler.HandlerError(
405+
return nexusrpc.HandlerError(
406406
err.message,
407-
type=nexusrpc.handler.HandlerErrorType.BAD_REQUEST,
407+
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
408408
cause=err,
409409
)
410410
elif err.status in [
411411
RPCStatusCode.ALREADY_EXISTS,
412412
RPCStatusCode.FAILED_PRECONDITION,
413413
RPCStatusCode.OUT_OF_RANGE,
414414
]:
415-
return nexusrpc.handler.HandlerError(
415+
return nexusrpc.HandlerError(
416416
err.message,
417-
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
417+
type=nexusrpc.HandlerErrorType.INTERNAL,
418418
cause=err,
419419
retryable=False,
420420
)
421421
elif err.status in [RPCStatusCode.ABORTED, RPCStatusCode.UNAVAILABLE]:
422-
return nexusrpc.handler.HandlerError(
422+
return nexusrpc.HandlerError(
423423
err.message,
424-
type=nexusrpc.handler.HandlerErrorType.UNAVAILABLE,
424+
type=nexusrpc.HandlerErrorType.UNAVAILABLE,
425425
cause=err,
426426
)
427427
elif err.status in [
@@ -436,37 +436,37 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.handler.HandlerE
436436
# we convert to internal because this is not a client auth error and happens
437437
# when the handler fails to auth with Temporal and should be considered
438438
# retryable.
439-
return nexusrpc.handler.HandlerError(
440-
err.message, type=nexusrpc.handler.HandlerErrorType.INTERNAL, cause=err
439+
return nexusrpc.HandlerError(
440+
err.message, type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
441441
)
442442
elif err.status == RPCStatusCode.NOT_FOUND:
443-
return nexusrpc.handler.HandlerError(
444-
err.message, type=nexusrpc.handler.HandlerErrorType.NOT_FOUND, cause=err
443+
return nexusrpc.HandlerError(
444+
err.message, type=nexusrpc.HandlerErrorType.NOT_FOUND, cause=err
445445
)
446446
elif err.status == RPCStatusCode.RESOURCE_EXHAUSTED:
447-
return nexusrpc.handler.HandlerError(
447+
return nexusrpc.HandlerError(
448448
err.message,
449-
type=nexusrpc.handler.HandlerErrorType.RESOURCE_EXHAUSTED,
449+
type=nexusrpc.HandlerErrorType.RESOURCE_EXHAUSTED,
450450
cause=err,
451451
)
452452
elif err.status == RPCStatusCode.UNIMPLEMENTED:
453-
return nexusrpc.handler.HandlerError(
453+
return nexusrpc.HandlerError(
454454
err.message,
455-
type=nexusrpc.handler.HandlerErrorType.NOT_IMPLEMENTED,
455+
type=nexusrpc.HandlerErrorType.NOT_IMPLEMENTED,
456456
cause=err,
457457
)
458458
elif err.status == RPCStatusCode.DEADLINE_EXCEEDED:
459-
return nexusrpc.handler.HandlerError(
459+
return nexusrpc.HandlerError(
460460
err.message,
461-
type=nexusrpc.handler.HandlerErrorType.UPSTREAM_TIMEOUT,
461+
type=nexusrpc.HandlerErrorType.UPSTREAM_TIMEOUT,
462462
cause=err,
463463
)
464464
else:
465-
return nexusrpc.handler.HandlerError(
465+
return nexusrpc.HandlerError(
466466
f"Unhandled RPC error status: {err.status}",
467-
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
467+
type=nexusrpc.HandlerErrorType.INTERNAL,
468468
cause=err,
469469
)
470-
return nexusrpc.handler.HandlerError(
471-
str(err), type=nexusrpc.handler.HandlerErrorType.INTERNAL, cause=err
470+
return nexusrpc.HandlerError(
471+
str(err), type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
472472
)

tests/nexus/test_handler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727
import httpx
2828
import nexusrpc
2929
import pytest
30-
from nexusrpc import OperationError, OperationErrorState, OperationInfo
30+
from nexusrpc import (
31+
HandlerError,
32+
HandlerErrorType,
33+
OperationError,
34+
OperationErrorState,
35+
OperationInfo,
36+
)
3137
from nexusrpc.handler import (
3238
CancelOperationContext,
3339
FetchOperationInfoContext,
3440
FetchOperationResultContext,
35-
HandlerError,
36-
HandlerErrorType,
3741
OperationHandler,
3842
StartOperationContext,
3943
service_handler,

tests/nexus/test_workflow_caller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,9 @@ class ErrorTestService:
11011101
@sync_operation
11021102
async def op(self, ctx: StartOperationContext, input: ErrorTestInput) -> None:
11031103
if input.action_in_sync_op == "raise_handler_error":
1104-
raise nexusrpc.handler.HandlerError(
1104+
raise nexusrpc.HandlerError(
11051105
"test",
1106-
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
1106+
type=nexusrpc.HandlerErrorType.INTERNAL,
11071107
)
11081108
elif input.action_in_sync_op == "raise_operation_error":
11091109
raise nexusrpc.OperationError(

0 commit comments

Comments
 (0)