2016-05-26 22:36:44 +00:00
|
|
|
import functools
|
2015-04-09 19:29:26 +00:00
|
|
|
|
|
|
|
class ServerError(Exception):
|
|
|
|
def __init__(self, message, relay):
|
|
|
|
self.message = message
|
|
|
|
self.relay = relay
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
|
|
|
|
|
|
|
def handle_server_error(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
def _wrap(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
except ServerError as e:
|
|
|
|
print("Server error (from %s):\n%s" % (e.relay, e.message))
|
|
|
|
return 1
|
|
|
|
return _wrap
|
2015-09-22 06:21:26 +00:00
|
|
|
|
|
|
|
class Timeout(Exception):
|
|
|
|
pass
|
|
|
|
|
2016-05-23 07:14:39 +00:00
|
|
|
class WelcomeError(Exception):
|
2016-05-26 22:36:44 +00:00
|
|
|
"""
|
|
|
|
The relay server told us to signal an error, probably because our version
|
|
|
|
is too old to possibly work. The server said:"""
|
|
|
|
pass
|
2016-05-23 07:14:39 +00:00
|
|
|
|
2015-09-22 06:21:26 +00:00
|
|
|
class WrongPasswordError(Exception):
|
|
|
|
"""
|
|
|
|
Key confirmation failed. Either you or your correspondent typed the code
|
|
|
|
wrong, or a would-be man-in-the-middle attacker guessed incorrectly. You
|
|
|
|
could try again, giving both your correspondent and the attacker another
|
|
|
|
chance.
|
|
|
|
"""
|
|
|
|
# or the data blob was corrupted, and that's why decrypt failed
|
2016-05-26 22:36:44 +00:00
|
|
|
pass
|
2015-09-22 06:21:26 +00:00
|
|
|
|
2016-06-02 21:07:27 +00:00
|
|
|
class KeyFormatError(Exception):
|
|
|
|
"""
|
|
|
|
The key you entered contains spaces. Magic-wormhole expects keys to be
|
2016-06-02 21:27:14 +00:00
|
|
|
separated by dashes. Please reenter the key you were given separating the
|
|
|
|
words with dashes.
|
2016-06-02 21:07:27 +00:00
|
|
|
"""
|
|
|
|
|
2015-09-22 06:21:26 +00:00
|
|
|
class ReflectionAttack(Exception):
|
|
|
|
"""An attacker (or bug) reflected our outgoing message back to us."""
|
|
|
|
|
|
|
|
class UsageError(Exception):
|
|
|
|
"""The programmer did something wrong."""
|
2016-02-16 05:40:57 +00:00
|
|
|
|
2016-05-24 05:53:00 +00:00
|
|
|
class WormholeClosedError(UsageError):
|
|
|
|
"""API calls may not be made after close() is called."""
|
|
|
|
|
2016-02-16 05:40:57 +00:00
|
|
|
class TransferError(Exception):
|
|
|
|
"""Something bad happened and the transfer failed."""
|