Closed
Bug 961648
Opened 10 years ago
Closed 10 years ago
Provide a helpful error message when test variables JSON file cannot be parsed
Categories
(Remote Protocol :: Marionette, defect)
Remote Protocol
Marionette
Tracking
(b2g-v1.3 fixed)
RESOLVED
FIXED
mozilla29
Tracking | Status | |
---|---|---|
b2g-v1.3 | --- | fixed |
People
(Reporter: davehunt, Assigned: adarshdinesh)
Details
(Whiteboard: [mentor=davehunt][lang=py])
Attachments
(2 files, 3 obsolete files)
54 bytes,
text/plain
|
Details | |
1.37 KB,
patch
|
davehunt
:
review+
|
Details | Diff | Splinter Review |
Currently the exception thrown when reading in an invalid JSON file isn't particularly helpful. We should at least output the path to the file being read and indicate that it is not of the expected format. To replicate: 1. Clone http://hg.mozilla.org/mozilla-central/ 2. cd mozilla-central/testing/marionette/client/marionette 3. Create an invalid testvars.json file (example attached) 4. ./venv_automation.sh python --testvars=testvars.json --binary=/path/to/firefox-bin tests/unit/unit-tests.ini Expected result: A message indicating the path to the JSON file and that it was not properly formatted. The exception message should be retained to indicate what's wrong with the file. Actual result: Traceback (most recent call last): File "runtests.py", line 33, in <module> cli() File "runtests.py", line 28, in cli runner = startTestRunner(runner_class, options, tests) File "runtests.py", line 18, in startTestRunner runner = runner_class(**vars(options)) File "runtests.py", line 13, in __init__ BaseMarionetteTestRunner.__init__(self, **kwargs) File "/Users/dhunt/workspace/mozilla/mozilla-central/testing/marionette/client/marionette/runner/base.py", line 541, in __init__ self.testvars = json.loads(f.read()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 2 column 2 (char 3)
Reporter | ||
Comment 2•10 years ago
|
||
Sure, I've assigned it to you. Let me know if you need any help by leaving a comment, or dropping into #ateam on irc.mozilla.org!
Assignee: nobody → adarshdinesh
Reporter | ||
Comment 3•10 years ago
|
||
Please review my first patch.
Attachment #8362616 -
Flags: review?(dave.hunt)
Reporter | ||
Comment 5•10 years ago
|
||
Comment on attachment 8362616 [details] [diff] [review] firstpatch.diff Review of attachment 8362616 [details] [diff] [review]: ----------------------------------------------------------------- Thanks for the quick turnaround. Just a couple of comments, but this is looking good! ::: testing/marionette/client/marionette/runner/base.py @@ +539,5 @@ > import json > + try: > + with open(testvars) as f: > + self.testvars = json.loads(f.read()) > + except Exception, e: We should only be catching the specific exceptions related to an invalid JSON format. See http://docs.python.org/2/library/json.html#encoders-and-decoders "If the data being deserialized is not a valid JSON document, a ValueError will be raised." Also, please use the following style: except E as N: @@ +541,5 @@ > + with open(testvars) as f: > + self.testvars = json.loads(f.read()) > + except Exception, e: > + raise Exception("JSON file (%s) is not properly formatted: %s" %(os.path.abspath(testvars), e)) > + Please remove this extraneous whitespace.
Attachment #8362616 -
Flags: review?(dave.hunt) → review-
1) Raising Exception if ValueError caught. 2) Following new style of excep (PEP 3110). 3) Removed the whitespace from last patch.
Attachment #8362616 -
Attachment is obsolete: true
Attachment #8363000 -
Flags: review?(dave.hunt)
Reporter | ||
Comment 7•10 years ago
|
||
Comment on attachment 8363000 [details] [diff] [review] second_patch.diff Review of attachment 8363000 [details] [diff] [review]: ----------------------------------------------------------------- Looks great, just a couple of nits I missed last time. With these fixed I think we can land it. ::: testing/marionette/client/marionette/runner/base.py @@ +540,5 @@ > + try: > + with open(testvars) as f: > + self.testvars = json.loads(f.read()) > + except ValueError as e: > + raise Exception("JSON file (%s) is not properly formatted: %s" %(os.path.abspath(testvars), e.message)) Nit: Please add a space after the % and before (os.path Nit: Could you limit the line length to as close to 80 characters as possible.
Attachment #8363000 -
Flags: review?(dave.hunt) → review-
1) Limited the line length to 80
Attachment #8363000 -
Attachment is obsolete: true
Attachment #8363620 -
Flags: review?(dave.hunt)
Reporter | ||
Comment 9•10 years ago
|
||
Comment on attachment 8363620 [details] [diff] [review] final_patch.diff Review of attachment 8363620 [details] [diff] [review]: ----------------------------------------------------------------- Looks good and works well. Can you please generate your patch according to https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#How_can_I_generate_a_patch_for_somebody_else_to_check-in_for_me.3F so that I can land it. Thanks!
Attachment #8363620 -
Flags: review?(dave.hunt) → review+
Assignee | ||
Comment 10•10 years ago
|
||
Patch generated according to https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#How_can_I_generate_a_patch_for_somebody_else_to_check-in_for_me.3F Its been a pleasure working with you. Thanks
Attachment #8365625 -
Flags: review?(dave.hunt)
Reporter | ||
Updated•10 years ago
|
Attachment #8363620 -
Attachment is obsolete: true
Reporter | ||
Comment 11•10 years ago
|
||
Comment on attachment 8365625 [details] [diff] [review] bug961648.patch Review of attachment 8365625 [details] [diff] [review]: ----------------------------------------------------------------- Thanks! Landed on inbound: https://hg.mozilla.org/integration/mozilla-inbound/rev/3e930acf2697
Attachment #8365625 -
Flags: review?(dave.hunt) → review+
Comment 12•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/3e930acf2697
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
Updated•10 years ago
|
status-b2g-v1.3:
--- → fixed
Updated•1 year ago
|
Product: Testing → Remote Protocol
You need to log in
before you can comment on or make changes to this bug.
Description
•