improve formatting of error messages
This commit is contained in:
parent
2cf11e85d3
commit
80c88387ef
|
@ -1,10 +1,10 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
start = time.time()
|
start = time.time()
|
||||||
import os, sys
|
import os, sys, textwrap
|
||||||
from twisted.internet.defer import maybeDeferred
|
from twisted.internet.defer import maybeDeferred
|
||||||
from twisted.internet.task import react
|
from twisted.internet.task import react
|
||||||
from ..errors import TransferError, WrongPasswordError, Timeout
|
from ..errors import TransferError, WrongPasswordError, WelcomeError, Timeout
|
||||||
from ..timing import DebugTiming
|
from ..timing import DebugTiming
|
||||||
from .cli_args import parser
|
from .cli_args import parser
|
||||||
top_import_finish = time.time()
|
top_import_finish = time.time()
|
||||||
|
@ -48,8 +48,17 @@ def run(reactor, argv, cwd, stdout, stderr, executable=None):
|
||||||
return res
|
return res
|
||||||
d.addBoth(_maybe_dump_timing)
|
d.addBoth(_maybe_dump_timing)
|
||||||
def _explain_error(f):
|
def _explain_error(f):
|
||||||
# these three errors don't print a traceback, just an explanation
|
# these errors don't print a traceback, just an explanation
|
||||||
f.trap(TransferError, WrongPasswordError, Timeout)
|
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)
|
print("ERROR:", f.value, file=stderr)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
d.addErrback(_explain_error)
|
d.addErrback(_explain_error)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import functools, textwrap
|
import functools
|
||||||
|
|
||||||
class ServerError(Exception):
|
class ServerError(Exception):
|
||||||
def __init__(self, message, relay):
|
def __init__(self, message, relay):
|
||||||
|
@ -21,8 +21,10 @@ class Timeout(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class WelcomeError(Exception):
|
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):
|
class WrongPasswordError(Exception):
|
||||||
"""
|
"""
|
||||||
|
@ -32,8 +34,7 @@ class WrongPasswordError(Exception):
|
||||||
chance.
|
chance.
|
||||||
"""
|
"""
|
||||||
# or the data blob was corrupted, and that's why decrypt failed
|
# or the data blob was corrupted, and that's why decrypt failed
|
||||||
def __init__(self):
|
pass
|
||||||
Exception.__init__(self, textwrap.dedent(self.__doc__.strip()))
|
|
||||||
|
|
||||||
class ReflectionAttack(Exception):
|
class ReflectionAttack(Exception):
|
||||||
"""An attacker (or bug) reflected our outgoing message back to us."""
|
"""An attacker (or bug) reflected our outgoing message back to us."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user