Skip to content

Commit 018b08f

Browse files
committed
modify: runner - stop on subprocess errors
1 parent 6348056 commit 018b08f

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

lighthouse/runner.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,34 @@ def __init__(self, url, form_factor='mobile', quiet=True):
2828
default is True
2929
"""
3030

31+
assert form_factor in ['mobile', 'desktop']
32+
3133
_, self.__report_path = tempfile.mkstemp(suffix='.json')
3234
self._run(url, form_factor, quiet)
3335
self.report = self._get_report()
3436
self._clean()
3537

3638
def _run(self, url, form_factor, quiet):
37-
subprocess.call([
38-
'lighthouse',
39-
url,
40-
'--quiet' if quiet else '',
41-
'--chrome-flags',
42-
'"--headless"',
43-
'--preset',
44-
'full',
45-
'--emulated-form-factor',
46-
form_factor,
47-
'--output',
48-
'json',
49-
'--output-path',
50-
'{0}'.format(self.__report_path),
51-
])
39+
report_path = self.__report_path
40+
41+
try:
42+
subprocess.check_call(' '.join([
43+
'lighthouse',
44+
url,
45+
'--quiet' if quiet else '',
46+
'--chrome-flags="--headless"',
47+
'--preset=full',
48+
'--emulated-form-factor={0}'.format(form_factor),
49+
'--output=json',
50+
'--output-path={0}'.format(report_path),
51+
]), shell=True)
52+
except subprocess.CalledProcessError as exc:
53+
msg = '''
54+
Command "{0}"
55+
returned an error code: {1},
56+
output: {2}
57+
'''.format(exc.cmd, exc.returncode, exc.output)
58+
raise RuntimeError(msg)
5259

5360
def _get_report(self):
5461
with open(self.__report_path, 'r') as fil:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lighthouse',
7-
version='1.0',
7+
version='1.0.1',
88
description='Lightouse runner',
99
author='Adam Cupiał',
1010
author_email='cupial.adam@gmail.com',

0 commit comments

Comments
 (0)