INNER CODE UNIT · Python

_write_output_or_exit

wiltodelta/remove-ai-watermarks · src/remove_ai_watermarks/cli.py:424

def _write_output_or_exit(
    output: Path,
    bgr: NDArray[Any],
    alpha: NDArray[Any] | None,
    display_source: Path | None = None,
) -> None:
    """Write the final image, or fail with a readable error instead of a traceback.

    `image_io.imwrite` is contractually NON-RAISING: it returns False when the codec
    rejects the image or the path cannot be written. Every caller here follows its write
    with `output.stat()` to report the size, so a silently-failed write (read-only
    directory, full disk) died with a bare `FileNotFoundError` traceback pointing at the
    stat, not at the write. Found by the Tier E adversarial sweep 2026-07-20.
    Regression: `tests/test_cli_robustness.py::TestFailedWriteIsReported`.

    `display_source` is the file whose decode produced `bgr`; its ICC profile and EXIF
    orientation ride along into the re-encoded output (issue #98)."""
    output.parent.mkdir(parents=True, exist_ok=True)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…