improve formatting of error messages
This commit is contained in:
parent
2cf11e85d3
commit
80c88387ef
|
@ -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)
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user