@@ -343,7 +343,7 @@ async def _operation_error_to_proto(
343
343
)
344
344
345
345
async def _handler_error_to_proto (
346
- self , err : nexusrpc .handler . HandlerError
346
+ self , err : nexusrpc .HandlerError
347
347
) -> temporalio .api .nexus .v1 .HandlerError :
348
348
return temporalio .api .nexus .v1 .HandlerError (
349
349
error_type = err .type .value ,
@@ -378,50 +378,50 @@ async def deserialize(
378
378
)
379
379
return input
380
380
except Exception as err :
381
- raise nexusrpc .handler . HandlerError (
381
+ raise nexusrpc .HandlerError (
382
382
"Data converter failed to decode Nexus operation input" ,
383
- type = nexusrpc .handler . HandlerErrorType .BAD_REQUEST ,
383
+ type = nexusrpc .HandlerErrorType .BAD_REQUEST ,
384
384
cause = err ,
385
385
retryable = False ,
386
386
) from err
387
387
388
388
389
389
# 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 :
391
391
# Based on sdk-typescript's convertKnownErrors:
392
392
# 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 ):
394
394
return err
395
395
elif isinstance (err , ApplicationError ):
396
- return nexusrpc .handler . HandlerError (
396
+ return nexusrpc .HandlerError (
397
397
# TODO(nexus-prerelease): what should message be?
398
398
err .message ,
399
- type = nexusrpc .handler . HandlerErrorType .INTERNAL ,
399
+ type = nexusrpc .HandlerErrorType .INTERNAL ,
400
400
cause = err ,
401
401
retryable = not err .non_retryable ,
402
402
)
403
403
elif isinstance (err , RPCError ):
404
404
if err .status == RPCStatusCode .INVALID_ARGUMENT :
405
- return nexusrpc .handler . HandlerError (
405
+ return nexusrpc .HandlerError (
406
406
err .message ,
407
- type = nexusrpc .handler . HandlerErrorType .BAD_REQUEST ,
407
+ type = nexusrpc .HandlerErrorType .BAD_REQUEST ,
408
408
cause = err ,
409
409
)
410
410
elif err .status in [
411
411
RPCStatusCode .ALREADY_EXISTS ,
412
412
RPCStatusCode .FAILED_PRECONDITION ,
413
413
RPCStatusCode .OUT_OF_RANGE ,
414
414
]:
415
- return nexusrpc .handler . HandlerError (
415
+ return nexusrpc .HandlerError (
416
416
err .message ,
417
- type = nexusrpc .handler . HandlerErrorType .INTERNAL ,
417
+ type = nexusrpc .HandlerErrorType .INTERNAL ,
418
418
cause = err ,
419
419
retryable = False ,
420
420
)
421
421
elif err .status in [RPCStatusCode .ABORTED , RPCStatusCode .UNAVAILABLE ]:
422
- return nexusrpc .handler . HandlerError (
422
+ return nexusrpc .HandlerError (
423
423
err .message ,
424
- type = nexusrpc .handler . HandlerErrorType .UNAVAILABLE ,
424
+ type = nexusrpc .HandlerErrorType .UNAVAILABLE ,
425
425
cause = err ,
426
426
)
427
427
elif err .status in [
@@ -436,37 +436,37 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.handler.HandlerE
436
436
# we convert to internal because this is not a client auth error and happens
437
437
# when the handler fails to auth with Temporal and should be considered
438
438
# 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
441
441
)
442
442
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
445
445
)
446
446
elif err .status == RPCStatusCode .RESOURCE_EXHAUSTED :
447
- return nexusrpc .handler . HandlerError (
447
+ return nexusrpc .HandlerError (
448
448
err .message ,
449
- type = nexusrpc .handler . HandlerErrorType .RESOURCE_EXHAUSTED ,
449
+ type = nexusrpc .HandlerErrorType .RESOURCE_EXHAUSTED ,
450
450
cause = err ,
451
451
)
452
452
elif err .status == RPCStatusCode .UNIMPLEMENTED :
453
- return nexusrpc .handler . HandlerError (
453
+ return nexusrpc .HandlerError (
454
454
err .message ,
455
- type = nexusrpc .handler . HandlerErrorType .NOT_IMPLEMENTED ,
455
+ type = nexusrpc .HandlerErrorType .NOT_IMPLEMENTED ,
456
456
cause = err ,
457
457
)
458
458
elif err .status == RPCStatusCode .DEADLINE_EXCEEDED :
459
- return nexusrpc .handler . HandlerError (
459
+ return nexusrpc .HandlerError (
460
460
err .message ,
461
- type = nexusrpc .handler . HandlerErrorType .UPSTREAM_TIMEOUT ,
461
+ type = nexusrpc .HandlerErrorType .UPSTREAM_TIMEOUT ,
462
462
cause = err ,
463
463
)
464
464
else :
465
- return nexusrpc .handler . HandlerError (
465
+ return nexusrpc .HandlerError (
466
466
f"Unhandled RPC error status: { err .status } " ,
467
- type = nexusrpc .handler . HandlerErrorType .INTERNAL ,
467
+ type = nexusrpc .HandlerErrorType .INTERNAL ,
468
468
cause = err ,
469
469
)
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
472
472
)
0 commit comments