mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-14 14:16:39 +00:00
Improve the failure case user experience
And test it
This commit is contained in:
parent
9cf0096603
commit
25a62001dd
@ -186,6 +186,30 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
|
||||
])
|
||||
self.assertEqual(rc_or_sig, 0)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_unknown_eliot_destination(self):
|
||||
out, err, rc_or_sig = yield self.run_bintahoe([
|
||||
"--eliot-destination=invalid:more",
|
||||
])
|
||||
self.assertEqual(1, rc_or_sig)
|
||||
self.assertIn("Unknown destination description", out)
|
||||
self.assertIn("invalid:more", out)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_malformed_eliot_destination(self):
|
||||
out, err, rc_or_sig = yield self.run_bintahoe([
|
||||
"--eliot-destination=invalid",
|
||||
])
|
||||
self.assertEqual(1, rc_or_sig)
|
||||
self.assertIn("must be formatted like", out)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_escape_in_eliot_destination(self):
|
||||
out, err, rc_or_sig = yield self.run_bintahoe([
|
||||
"--eliot-destination=file:\\foo",
|
||||
])
|
||||
self.assertEqual(1, rc_or_sig)
|
||||
self.assertIn("Unsupported escape character", out)
|
||||
|
||||
|
||||
class CreateNode(unittest.TestCase):
|
||||
|
@ -65,6 +65,9 @@ from eliot._validation import (
|
||||
ValidationError,
|
||||
)
|
||||
|
||||
from twisted.python.usage import (
|
||||
UsageError,
|
||||
)
|
||||
from twisted.python.filepath import (
|
||||
FilePath,
|
||||
)
|
||||
@ -287,9 +290,12 @@ def opt_eliot_destination(self, description):
|
||||
"""
|
||||
Add an Eliot logging destination. May be given more than once.
|
||||
"""
|
||||
self.setdefault("destinations", []).append(
|
||||
_parse_destination_description(description)
|
||||
)
|
||||
try:
|
||||
destination = _parse_destination_description(description)
|
||||
except Exception as e:
|
||||
raise UsageError(str(e))
|
||||
else:
|
||||
self.setdefault("destinations", []).append(destination)
|
||||
|
||||
|
||||
def opt_help_eliot_destinations(self):
|
||||
@ -399,7 +405,13 @@ class _DestinationParser(object):
|
||||
def parse(self, description):
|
||||
description = description.decode(u"ascii")
|
||||
|
||||
kind, args = description.split(u":", 1)
|
||||
try:
|
||||
kind, args = description.split(u":", 1)
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
u"Eliot destination description must be formatted like "
|
||||
u"<kind>:<args>."
|
||||
)
|
||||
try:
|
||||
parser = getattr(self, u"_parse_{}".format(kind))
|
||||
except AttributeError:
|
||||
|
Loading…
x
Reference in New Issue
Block a user