Skip to content

Commit e467550

Browse files
committed
Raise ToolError and exit non-zero on ecosystem panics
Summary -- The huge number of changes in #22205 (comment) should have obviously been a red flag, but I think it would be nice if CI failed when new ecosystem panics were introduced. This PR adds a check for diagnostic lines that start with `panic: Panicked at crates/`, raises a `ToolError` if any are found in the results from the comparison executable, and then also exits non-zero if any errors are returned. If exiting non-zero is going too far, we could also just raise the `ToolError`, as that will at least trigger this message, which was not the case on the PLR1712 PR: https://github.com/astral-sh/ruff/blob/f14edd8661e2803254f89265548c7487f47a09f6/python/ruff-ecosystem/ruff_ecosystem/check.py#L103-L106 Another option would be not to exit zero if Ruff panics, even if `--exit-zero` is used, but I saw that ty has the same behavior and assumed that that was intentional. Test Plan -- Local testing on the 0.15.3 tag showing that ruff-ecosystem exited non-zero. I can also introduce a panic into a lint rule to test this in CI
1 parent f14edd8 commit e467550

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

python/ruff-ecosystem/ruff_ecosystem/check.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
r"^(?P<diff>[+-])? ?(?P<location>.*): (?P<code>[A-Z]{1,4}[0-9]{3,4}|[a-z\-]+:)(?P<fixable> \[\*\])? (?P<message>.*)"
4949
)
5050

51+
PANIC_DIAGNOSTIC_LINE_RE = re.compile(r"^[^:]+: panic: Panicked at crates/")
52+
5153
CHECK_VIOLATION_FIX_INDICATOR = " [*]"
5254

5355
GITHUB_MAX_COMMENT_LENGTH = 65536 # characters
@@ -529,6 +531,10 @@ async def compare_check(
529531
comparison_task.result(),
530532
)
531533

534+
for line in comparison_output:
535+
if PANIC_DIAGNOSTIC_LINE_RE.match(line):
536+
raise ToolError(line)
537+
532538
diff = Diff.from_pair(baseline_output, comparison_output)
533539

534540
return Comparison(diff=diff, repo=cloned_repo)

python/ruff-ecosystem/ruff_ecosystem/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ def entrypoint():
105105
for signal in [SIGINT, SIGTERM]:
106106
loop.add_signal_handler(signal, main_task.cancel)
107107
try:
108-
loop.run_until_complete(main_task)
108+
had_errors = loop.run_until_complete(main_task)
109109
finally:
110110
loop.close()
111111

112+
if had_errors:
113+
exit(1)
114+
112115

113116
def parse_args() -> argparse.Namespace:
114117
parser = argparse.ArgumentParser(

python/ruff-ecosystem/ruff_ecosystem/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def limited_parallelism(coroutine: Awaitable[T]) -> T:
9696
case _:
9797
raise ValueError(f"Unknown output format {format}")
9898

99-
return None
99+
return bool(result.errored)
100100

101101

102102
async def clone_and_compare(

0 commit comments

Comments
 (0)