execution-create and run_action API's if called with bad formatted json file raises ValueError

Bug #1705989 reported by Dinesh Bhor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mistralclient
New
Undecided
Dinesh Bhor

Bug Description

API's like "execution-create" and "run_action" takes input in the json format and if they called with bad formatted json file then it raises ValueError which is not user friendly and doesn't give any clue to user what is wrong.

Steps to reproduce:

Command:
mistral --debug execution-create std.delete_instance input.json

input.json:

{
     vm_namei: "my_test_virtual_machine"
}

mistralclient debug logs:

Traceback (most recent call last):
  File "/usr/local/bin/mistral", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/mistralclient/shell.py", line 694, in main
    return MistralShell().run(argv)
  File "/usr/local/lib/python2.7/dist-packages/cliff/app.py", line 279, in run
    result = self.run_subcommand(remainder)
  File "/usr/local/lib/python2.7/dist-packages/cliff/app.py", line 400, in run_subcommand
    result = cmd.run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/cliff/display.py", line 113, in run
    column_names, data = self.take_action(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/mistralclient/commands/v2/executions.py", line 187, in take_action
    wf_input = utils.load_json(parsed_args.workflow_input)
  File "/usr/local/lib/python2.7/dist-packages/mistralclient/utils.py", line 87, in load_json
    return json.load(fh)
  File "/usr/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 2 column 5 (char 6)

It looks like if it fails to parse the json file properly then "json.load" returns the ValueError
which is not handled properly. It should be caught in "utils.load_json" and something like "Failed to parse input json file" should be returned.

Changed in python-mistralclient:
assignee: nobody → Dinesh Bhor (dinesh-bhor)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.