diff --git a/src/wormhole/cli/runner.py b/src/wormhole/cli/runner.py index ac984c1..a15a50e 100644 --- a/src/wormhole/cli/runner.py +++ b/src/wormhole/cli/runner.py @@ -4,7 +4,8 @@ start = time.time() import os, sys, textwrap from twisted.internet.defer import maybeDeferred from twisted.internet.task import react -from ..errors import TransferError, WrongPasswordError, WelcomeError, Timeout +from ..errors import (TransferError, WrongPasswordError, WelcomeError, Timeout, + KeyFormatError) from ..timing import DebugTiming from .cli_args import parser top_import_finish = time.time() @@ -49,7 +50,8 @@ def run(reactor, argv, cwd, stdout, stderr, executable=None): d.addBoth(_maybe_dump_timing) def _explain_error(f): # these errors don't print a traceback, just an explanation - f.trap(TransferError, WrongPasswordError, WelcomeError, Timeout) + f.trap(TransferError, WrongPasswordError, WelcomeError, Timeout, + KeyFormatError) if f.check(WrongPasswordError): msg = textwrap.fill("ERROR: " + textwrap.dedent(f.value.__doc__)) print(msg, file=stderr) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index fafb966..1607413 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -15,7 +15,7 @@ from . import __version__ from . import codes #from .errors import ServerError, Timeout from .errors import (WrongPasswordError, UsageError, WelcomeError, - WormholeClosedError) + WormholeClosedError, KeyFormatError) from .timing import DebugTiming from .util import (to_bytes, bytes_to_hexstr, hexstr_to_bytes, dict_to_bytes, bytes_to_dict) @@ -476,6 +476,13 @@ class _Wormhole: def _event_learned_code(self, code): self._timing.add("code established") + # bail out early if the password contains spaces... + # this should raise a useful error + if ' ' in code: + raise KeyFormatError( + "code (%s) contains spaces. Words must be separated by dashes" + % code + ) self._code = code mo = re.search(r'^(\d+)-', code) if not mo: