def convert_to_fcr_exception()

in fbnet/command_runner/exceptions.py [0:0]


def convert_to_fcr_exception(e: Exception) -> FcrBaseException:
    """
    Convert all generic exceptions to FcrBaseException types
    Leaves FcrBaseException types unchanged
    """
    if isinstance(e, FcrBaseException):
        return e
    elif isinstance(e, PermissionError):
        # use str(e) for known exceptions to keep exception messages clean
        return PermissionErrorException(str(e))
    elif isinstance(e, ValueError):
        return ValueErrorException(str(e))
    elif isinstance(e, AssertionError):
        return AssertionErrorException(str(e))
    elif isinstance(e, LookupError) or isinstance(e, KeyError):
        return LookupErrorException(str(e))
    elif isinstance(e, NotImplementedError):
        return NotImplementedErrorException(str(e))
    elif isinstance(e, asyncssh.misc.DisconnectError):
        return ConnectionErrorException(str(e))
    elif isinstance(e, TypeError):
        return TypeErrorException(str(e))
    elif isinstance(e, AttributeError):
        return AttributeErrorException(str(e))
    elif isinstance(e, TimeoutError):
        return TimeoutErrorException(str(e))
    elif isinstance(e, RuntimeError):
        # keep RuntimeError as last elif case to avoid interfering
        # with conversion of other RuntimeError-derived exceptions
        # and catch any unidentified RuntimeError-derived exceptions
        return RuntimeErrorException(str(e))
    else:
        # use repr(e) for unknown exceptions to preserve exception information
        return UnknownException(repr(e))