Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Issue 2768883004: json: Improve error handling and adding ability to limit log output.

Created:
3 years, 9 months ago by mithro
Modified:
3 years, 9 months ago
CC:
chromium-reviews, infra-reviews+recipes-py_chromium.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

json: Improve error handling and adding ability to limit log output. When json parsing fails it can be hard to see the reason why. Adding some explicit handling of common error cases (empty file and None input) makes it easier to see the issue. The error output should always be included even when add_json_log is false otherwise things like empty or missing json files are silently ignored and cause very weird and hard to debug issues later in recipes code. Adding this reveals numerous issues where this state is being accidentally ignored already. With large json files there is the temptation to use add_json_log=False to reduce the output. This makes it very hard to debug issues with the json as you have no idea what the contents even looked like. By adding a max output size allows making this trade off more easily. The line snipping code is in utilities to allow it to be used in other similar places.

Patch Set 1 #

Total comments: 11
Unified diffs Side-by-side diffs Delta from patch set Stats (+194 lines, -10 lines) Patch
M recipe_engine/unittests/util_test.py View 1 chunk +42 lines, -0 lines 0 comments Download
M recipe_engine/util.py View 2 chunks +57 lines, -0 lines 0 comments Download
M recipe_modules/json/api.py View 4 chunks +34 lines, -6 lines 9 comments Download
M recipe_modules/json/example.py View 2 chunks +19 lines, -0 lines 0 comments Download
M recipe_modules/json/example.expected/basic.json View 1 chunk +34 lines, -4 lines 0 comments Download
M recipe_modules/json/test_api.py View 1 chunk +8 lines, -0 lines 2 comments Download

Messages

Total messages: 8 (3 generated)
mithro
Hi, I've recently had a whole bunch of issues dealing with json files in recipes. ...
3 years, 9 months ago (2017-03-23 11:52:03 UTC) #3
Paweł Hajdan Jr.
https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py File recipe_modules/json/api.py (right): https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#newcode5 recipe_modules/json/api.py:5: import sys nit: sort https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#newcode73 recipe_modules/json/api.py:73: explain_invalid = 'input ...
3 years, 9 months ago (2017-03-23 12:22:13 UTC) #5
iannucci
https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py File recipe_modules/json/api.py (right): https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#newcode69 recipe_modules/json/api.py:69: explain_invalid = 'input was None' This isn't a good ...
3 years, 9 months ago (2017-03-23 19:38:00 UTC) #6
iannucci
On 2017/03/23 19:38:00, iannucci wrote: > https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py > File recipe_modules/json/api.py (right): > > https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#newcode69 > ...
3 years, 9 months ago (2017-03-23 19:38:54 UTC) #7
iannucci
3 years, 9 months ago (2017-03-23 19:44:13 UTC) #8
https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py
File recipe_modules/json/api.py (right):

https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#...
recipe_modules/json/api.py:73: explain_invalid = 'input was invalid'
On 2017/03/23 12:22:12, Paweł Hajdan Jr. wrote:
> Why not propagate the original exception then?

The exception is reported below.

But yes; it might make sense to raise StepError("json output was invalid:
<explaination>")?

https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/api.py#...
recipe_modules/json/api.py:137: def output(self, add_json_log=True,
force_full_log=False, name=None, leak_to=None):
On 2017/03/23 12:22:12, Paweł Hajdan Jr. wrote:
> Remember to propagate force_full_log.

Maybe `limit_log=<default amount with None meaning unlimited>`?

I would also make this the last kwarg in case someone is using this method with
positional arguments.

https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/test_ap...
File recipe_modules/json/test_api.py (right):

https://codereview.chromium.org/2768883004/diff/1/recipe_modules/json/test_ap...
recipe_modules/json/test_api.py:33: # FIXME: How do I get None into the data?
On 2017/03/23 12:22:12, Paweł Hajdan Jr. wrote:
> What happens if you just use None below instead of '' ?

That's what I would expect as well... however I would also expect that passing
None to invalid() above will also work?

Powered by Google App Engine
This is Rietveld 408576698