Skip to content

Commit

Permalink
Add try..except block in pre-commit linter (oppia#6019)
Browse files Browse the repository at this point in the history
* Add try..except block in pre-commit linter

Add try..except block to handle the case when
there are no Python, JavaScript or CSS files to lint.

* Modify comment

* Move comment inside the try..except block
  • Loading branch information
apb7 authored and nithusha21 committed Dec 21, 2018
1 parent f760bd8 commit 8a58279
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/pre_commit_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,15 @@ def _pre_commit_linter(all_files):

TIMEOUT_MULTIPLIER = 1000
for file_group, process in zip(file_groups_to_lint, linting_processes):
# Require timeout parameter to prevent against endless waiting for the
# linting function to return.
process.join(timeout=(
TIMEOUT_MULTIPLIER * len(file_group) / number_of_files_to_lint))
# try..except block is needed to catch ZeroDivisionError
# when there are no CSS, HTML, JavaScript and Python files to lint.
try:
# Require timeout parameter to prevent against endless
# waiting for the linting function to return.
process.join(timeout=(
TIMEOUT_MULTIPLIER * len(file_group) / number_of_files_to_lint))
except ZeroDivisionError:
break

js_messages = []
while not js_stdout.empty():
Expand Down

0 comments on commit 8a58279

Please sign in to comment.