Skip to content

Official Codebase of 3DCodeVerse

Python

cli: make refuses an --image that is not a readable image before the run exists

gaoypeng53d9defb7ade
diff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.py
index c7933680..a51f62a1 100644
--- a/harness/codeverse3d/cli/main.py
+++ b/harness/codeverse3d/cli/main.py
@@ -339,6 +339,13 @@ def make(
for p in image:
if not p.is_file():
raise C.CliError(f"reference image not found: {p}")
+ from PIL import Image, UnidentifiedImageError
+
+ try: # a file that is no image reached the planner and the provider, and failed there
+ with Image.open(p) as im:
+ im.verify()
+ except (UnidentifiedImageError, OSError, SyntaxError) as e:
+ raise C.CliError(f"reference image is not a readable image: {p} ({e})") from None
if language is None:
language = TRACK_LANGUAGES[track][0]
run_slug = C.make_slug(prompt, track.value, language.value, slug)
diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.py
index 176f55d5..7a97e28e 100644
--- a/harness/tests/flywheel_cli/test_cli.py
+++ b/harness/tests/flywheel_cli/test_cli.py
@@ -569,3 +569,10 @@ def test_a_zero_minute_budget_is_refused(made_run, tmp_path: Path):
runs, run_dir = made_run()
r = runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs), "--max-minutes", "0"])
assert r.exit_code == 2 and "--max-minutes" in r.output
+
+
+def test_a_reference_that_is_not_an_image_is_refused_before_the_run_exists(tmp_path: Path):
+ bad = tmp_path / "ref.png"
+ bad.write_text("not an image")
+ r = runner.invoke(app, ["make", "a cup", "--image", str(bad), "--no-run", "--runs-dir", str(tmp_path / "runs"), "--slug", "i"])
+ assert r.exit_code == 1 and "not a readable image" in r.output and not (tmp_path / "runs" / "i").exists()