fix raising remote exceptions
This commit is contained in:
parent
4a567f7ab1
commit
f1980f524e
2 changed files with 14 additions and 2 deletions
|
@ -1,4 +1,11 @@
|
||||||
import binascii
|
import binascii
|
||||||
|
import exceptions
|
||||||
|
|
||||||
|
# this is a dict of {"exceptions.<exception class name>": exception class} items used to raise
|
||||||
|
# remote built-in exceptions locally
|
||||||
|
BUILTIN_EXCEPTIONS = {
|
||||||
|
"exceptions.%s" % e: getattr(exceptions, e) for e in dir(exceptions) if not e.startswith("_")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DecodeError(Exception):
|
class DecodeError(Exception):
|
||||||
|
|
|
@ -11,7 +11,7 @@ import encoding
|
||||||
import msgtypes
|
import msgtypes
|
||||||
import msgformat
|
import msgformat
|
||||||
from contact import Contact
|
from contact import Contact
|
||||||
from error import UnknownRemoteException, TimeoutError
|
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError
|
||||||
from delay import Delay
|
from delay import Delay
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -246,7 +246,12 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
||||||
df.callback((message, address))
|
df.callback((message, address))
|
||||||
elif isinstance(message, msgtypes.ErrorMessage):
|
elif isinstance(message, msgtypes.ErrorMessage):
|
||||||
# The RPC request raised a remote exception; raise it locally
|
# The RPC request raised a remote exception; raise it locally
|
||||||
remoteException = Exception(message.response)
|
if message.exceptionType in BUILTIN_EXCEPTIONS:
|
||||||
|
exception_type = BUILTIN_EXCEPTIONS[message.exceptionType]
|
||||||
|
else:
|
||||||
|
exception_type = UnknownRemoteException
|
||||||
|
remoteException = exception_type(message.response)
|
||||||
|
log.error("Remote exception (%s): %s", address, remoteException)
|
||||||
df.errback(remoteException)
|
df.errback(remoteException)
|
||||||
else:
|
else:
|
||||||
# We got a result from the RPC
|
# We got a result from the RPC
|
||||||
|
|
Loading…
Add table
Reference in a new issue