Add a specially handled `ContextCancelled` error

transport_hardening
Tyler Goodlet 2021-06-13 18:01:49 -04:00
parent c92fc33b7c
commit e74e93f857
1 changed files with 3 additions and 10 deletions

View File

@ -1,7 +1,7 @@
""" """
Our classy exception set. Our classy exception set.
""" """
from typing import Dict, Any, Optional, Type from typing import Dict, Any, Optional
import importlib import importlib
import builtins import builtins
import traceback import traceback
@ -18,7 +18,7 @@ class RemoteActorError(Exception):
def __init__( def __init__(
self, self,
message: str, message: str,
suberror_type: Optional[Type[BaseException]] = None, suberror_type: Optional[Exception] = None,
**msgdata **msgdata
) -> None: ) -> None:
@ -37,10 +37,6 @@ class InternalActorError(RemoteActorError):
""" """
class TransportClosed(trio.ClosedResourceError):
"Underlying channel transport was closed prior to use"
class ContextCancelled(RemoteActorError): class ContextCancelled(RemoteActorError):
"Inter-actor task context cancelled itself on the callee side." "Inter-actor task context cancelled itself on the callee side."
@ -70,22 +66,19 @@ def pack_error(exc: BaseException) -> Dict[str, Any]:
def unpack_error( def unpack_error(
msg: Dict[str, Any], msg: Dict[str, Any],
chan=None, chan=None,
err_type=RemoteActorError err_type=RemoteActorError
) -> Exception: ) -> Exception:
"""Unpack an 'error' message from the wire """Unpack an 'error' message from the wire
into a local ``RemoteActorError``. into a local ``RemoteActorError``.
""" """
error = msg['error'] error = msg['error']
tb_str = error.get('tb_str', '') tb_str = error.get('tb_str', '')
message = f"{chan.uid}\n" + tb_str message = f"{chan.uid}\n" + tb_str
type_name = error['type_str'] type_name = error['type_str']
suberror_type: Type[BaseException] = Exception suberror_type = Exception
if type_name == 'ContextCancelled': if type_name == 'ContextCancelled':
err_type = ContextCancelled err_type = ContextCancelled