Bug 1369710 - [mozlint] Ensure that a valid path is entered. r=ahal
authorDyex <Dyex719@gmail.com>
Tue, 08 Aug 2017 19:20:31 +0530
changeset 373922 9f2c22f4ef01
parent 373921 32452cb511f5
child 373923 8b22f1b5e9f3
push id454
push userasasaki@mozilla.com
push dateTue, 08 Aug 2017 22:52:59 +0000
reviewersahal
bugs1369710
milestone57.0a1
Bug 1369710 - [mozlint] Ensure that a valid path is entered. r=ahal MozReview-Commit-ID: 6HOE9hmOkCx
python/mozlint/mozlint/cli.py
--- a/python/mozlint/mozlint/cli.py
+++ b/python/mozlint/mozlint/cli.py
@@ -108,16 +108,22 @@ def find_linters(linters=None):
 
 
 def run(paths, linters, fmt, outgoing, workdir, **lintargs):
     from mozlint import LintRoller, formatters
 
     lint = LintRoller(**lintargs)
     lint.read(find_linters(linters))
 
+    # Check if the path that is entered is a valid one.
+    invalid_paths = [path for path in paths if not os.path.exists(path)]
+    if invalid_paths:
+        print("Error: The following paths do not exist:\n{}".format("\n".join(invalid_paths)))
+        return 1
+
     # run all linters
     results = lint.roll(paths, outgoing=outgoing, workdir=workdir)
     formatter = formatters.get(fmt)
 
     # Encode output with 'replace' to avoid UnicodeEncodeErrors on
     # environments that aren't using utf-8.
     print(formatter(results, failed=lint.failed).encode(
         sys.stdout.encoding or 'ascii', 'replace'))