Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Ensure the return code is handled correctly to account for any unexpected behavior. #36068

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions scripts/eslint.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,25 @@ def run_eslint():
)

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

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


if __name__ == "__main__":
Expand Down
Loading