Bug 1303725 - Make mach eslint output more helpful in case of an error. r?miker draft
authorPhilipp Kewisch <mozilla@kewis.ch>
Mon, 19 Sep 2016 22:17:40 +0200
changeset 415182 9f8eb21561aa76e77cbde64a2cd485d21f80c935
parent 415181 437db7038f7647c6c67d23e9b88e09f026695908
child 531559 f5b63033f3a517ed1c2ccbb9eb430dbca04403b6
push id29811
push usermozilla@kewis.ch
push dateMon, 19 Sep 2016 20:36:11 +0000
reviewersmiker
bugs1303725
milestone51.0a1
Bug 1303725 - Make mach eslint output more helpful in case of an error. r?miker MozReview-Commit-ID: KvTrBfnPjtn
tools/lint/eslint.lint
--- a/tools/lint/eslint.lint
+++ b/tools/lint/eslint.lint
@@ -13,16 +13,21 @@ import subprocess
 import sys
 from distutils.version import LooseVersion
 
 import which
 from mozprocess import ProcessHandler
 
 from mozlint import result
 
+ESLINT_ERROR_MESSAGE = """
+An error occurred running eslint. Please check the following error messages:
+
+{}
+""".strip()
 
 ESLINT_NOT_FOUND_MESSAGE = """
 Could not find eslint!  We looked at the --binary option, at the ESLINT
 environment variable, and then at your local node_modules path. Please Install
 eslint and needed plugins with:
 
 mach eslint --setup
 
@@ -320,18 +325,24 @@ def lint(paths, binary=None, fix=None, s
     signal.signal(signal.SIGINT, orig)
 
     try:
         proc.wait()
     except KeyboardInterrupt:
         proc.kill()
         return []
 
+    try:
+        jsonresult = json.loads(proc.output[0] or '[]')
+    except ValueError:
+        print(ESLINT_ERROR_MESSAGE.format("\n".join(proc.output)))
+        return 1
+
     results = []
-    for obj in json.loads(proc.output[0] or '[]'):
+    for obj in jsonresult:
         errors = obj['messages']
 
         for err in errors:
             err.update({
                 'hint': err.get('fix'),
                 'level': 'error' if err['severity'] == 2 else 'warning',
                 'lineno': err.get('line'),
                 'path': obj['filePath'],