Skip to content

Commit 38dc4ea

Browse files
authored
chore: Ensure the return code is handled correctly to account for any unexpected behavior. (#36068)
* chore: Ensure the return code is handled correctly to account for any unexpected behavior.
1 parent e934c07 commit 38dc4ea

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

scripts/eslint.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ def run_eslint():
4949
)
5050

5151
print(result.stdout)
52-
last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else ""
53-
regex = r'^\d+'
54-
try:
55-
num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0
56-
# Fail if number of violations is greater than the limit
57-
if num_violations > violations_limit:
58-
fail_quality(
59-
"FAILURE: Too many eslint violations ({count}).\nThe limit is {violations_limit}.".format(count=num_violations, violations_limit=violations_limit))
60-
else:
61-
print(f"successfully run eslint with '{num_violations}' violations")
52+
if result.returncode == 0:
53+
fail_quality("No eslint violations found. This is unexpected... are you sure eslint is running correctly?")
54+
elif result.returncode == 1:
55+
last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else ""
56+
regex = r'^\d+'
57+
try:
58+
num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0
59+
# Fail if number of violations is greater than the limit
60+
if num_violations > violations_limit:
61+
fail_quality("FAILURE: Too many eslint violations ({count}).\nThe limit is {violations_limit}.".format(count=num_violations, violations_limit=violations_limit))
62+
else:
63+
print(f"successfully run eslint with '{num_violations}' violations")
6264

63-
# An AttributeError will occur if the regex finds no matches.
64-
except (AttributeError, ValueError):
65-
fail_quality(f"FAILURE: Number of eslint violations could not be found in '{last_line}'")
65+
# An AttributeError will occur if the regex finds no matches.
66+
except (AttributeError, ValueError):
67+
fail_quality(f"FAILURE: Number of eslint violations could not be found in '{last_line}'")
68+
else:
69+
print(f"Unexpected ESLint failure with exit code {result.returncode}.")
70+
fail_quality(f"Unexpected error: {result.stderr.strip()}")
6671

6772

6873
if __name__ == "__main__":

0 commit comments

Comments
 (0)