Skip to content
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
fuzz-parser: catch exceptions from pysource-minimize
  • Loading branch information
AlexWaygood committed Nov 25, 2024
commit e1f24a087cdc110f99d56b47034af1bd70f38c9a
16 changes: 15 additions & 1 deletion scripts/fuzz-parser/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from __future__ import annotations

import argparse
import ast
import concurrent.futures
import enum
import subprocess
Expand All @@ -30,6 +31,7 @@
from typing import NewType, assert_never

from pysource_codegen import generate as generate_random_code
from pysource_minimize import CouldNotMinimize
from pysource_minimize import minimize as minimize_repro
from rich_argparse import RawDescriptionRichHelpFormatter
from termcolor import colored
Expand Down Expand Up @@ -150,7 +152,19 @@ def fuzz_code(seed: Seed, args: ResolvedCliArgs) -> FuzzResult:
executable=args.executable,
executable_path=args.test_executable_path,
)
maybe_bug = MinimizedSourceCode(minimize_repro(code, callback))
try:
maybe_bug = MinimizedSourceCode(minimize_repro(code, callback))
except CouldNotMinimize as e:
# This is to double-check that there isn't a bug in
# `pysource-minimize`/`pysource-codegen`.
# `pysource-minimize` *should* never produce code that's invalid syntax.
try:
ast.parse(code)
except SyntaxError:
raise e from None
else:
maybe_bug = MinimizedSourceCode(code)

else:
maybe_bug = None
return FuzzResult(seed, maybe_bug, args.executable)
Expand Down