diff --git a/src/wormhole/cli/runner.py b/src/wormhole/cli/runner.py index b77b5f2..ac984c1 100644 --- a/src/wormhole/cli/runner.py +++ b/src/wormhole/cli/runner.py @@ -1,10 +1,10 @@ from __future__ import print_function import time start = time.time() -import os, sys +import os, sys, textwrap from twisted.internet.defer import maybeDeferred from twisted.internet.task import react -from ..errors import TransferError, WrongPasswordError, Timeout +from ..errors import TransferError, WrongPasswordError, WelcomeError, Timeout from ..timing import DebugTiming from .cli_args import parser top_import_finish = time.time() @@ -48,9 +48,18 @@ def run(reactor, argv, cwd, stdout, stderr, executable=None): return res d.addBoth(_maybe_dump_timing) def _explain_error(f): - # these three errors don't print a traceback, just an explanation - f.trap(TransferError, WrongPasswordError, Timeout) - print("ERROR:", f.value, file=stderr) + # these errors don't print a traceback, just an explanation + f.trap(TransferError, WrongPasswordError, WelcomeError, Timeout) + if f.check(WrongPasswordError): + msg = textwrap.fill("ERROR: " + textwrap.dedent(f.value.__doc__)) + print(msg, file=stderr) + elif f.check(WelcomeError): + msg = textwrap.fill("ERROR: " + textwrap.dedent(f.value.__doc__)) + print(msg, file=stderr) + print(file=stderr) + print(str(f.value), file=stderr) + else: + print("ERROR:", f.value, file=stderr) raise SystemExit(1) d.addErrback(_explain_error) d.addCallback(lambda _: 0) diff --git a/src/wormhole/errors.py b/src/wormhole/errors.py index 141523d..08ebae7 100644 --- a/src/wormhole/errors.py +++ b/src/wormhole/errors.py @@ -1,4 +1,4 @@ -import functools, textwrap +import functools class ServerError(Exception): def __init__(self, message, relay): @@ -21,8 +21,10 @@ class Timeout(Exception): pass class WelcomeError(Exception): - """The server told us to signal an error, probably because our version is - too old to possibly work.""" + """ + The relay server told us to signal an error, probably because our version + is too old to possibly work. The server said:""" + pass class WrongPasswordError(Exception): """ @@ -32,8 +34,7 @@ class WrongPasswordError(Exception): chance. """ # or the data blob was corrupted, and that's why decrypt failed - def __init__(self): - Exception.__init__(self, textwrap.dedent(self.__doc__.strip())) + pass class ReflectionAttack(Exception): """An attacker (or bug) reflected our outgoing message back to us."""