Clearer error message when unable to parse JSON
Using a non-existing file currently results in a cryptic message. Change-Id: I0489380d3a3ac1c9286e754c488df68f2b85c22f
This commit is contained in:
parent
17856e5d9f
commit
b3e955971c
@ -383,8 +383,8 @@ def handle_json_or_file_arg(json_arg):
|
||||
try:
|
||||
json_arg = json.loads(json_arg)
|
||||
except ValueError as e:
|
||||
err = (_("For JSON: '%(string)s', error: '%(err)s'") %
|
||||
{'err': e, 'string': json_arg})
|
||||
err = (_("Value '%(string)s' is not a file and cannot be parsed "
|
||||
"as JSON: '%(err)s'") % {'err': e, 'string': json_arg})
|
||||
raise exc.InvalidAttribute(err)
|
||||
|
||||
return json_arg
|
||||
|
@ -342,7 +342,7 @@ class HandleJsonFileTest(test_utils.BaseTestCase):
|
||||
def test_handle_json_or_file_arg_bad_json(self):
|
||||
cleansteps = 'foo'
|
||||
self.assertRaisesRegex(exc.InvalidAttribute,
|
||||
'For JSON',
|
||||
'is not a file and cannot be parsed as JSON',
|
||||
utils.handle_json_or_file_arg, cleansteps)
|
||||
|
||||
def test_handle_json_or_file_arg_file(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user