pbakaus/impeccable · error

comp-diff: cannot read comp

Error message

comp-diff: cannot read comp {comp_path}: {e}

What it means

After argument validation, comp-diff reads the comp (reference) PNG via read_png. If the file cannot be read or decoded as a PNG, it reports the path plus the underlying io error and exits 1. This isolates which of the two images failed so the user is not left guessing.

Solutions

  1. Verify the comp path exists: `ls -l <path>` (from the same working directory comp-diff runs in).
  2. Confirm the file is a valid PNG (`file <path>` shows 'PNG image data').
  3. Re-capture or re-export the reference screenshot as a real PNG.
  4. Fix filesystem permissions if read access is denied.

Example fix

// before
$ impeccable comp-diff --comp ./missing-ref.png --build ./build.png
comp-diff: cannot read comp ./missing-ref.png: No such file or directory
// after
$ impeccable comp-diff --comp ./.impeccable/comp/ref.png --build ./build.png
Defensive patterns

Strategy: try-catch

When it happens

Trigger: `--comp <path>` points at a nonexistent file, an unreadable path (permissions), a directory, a non-PNG file (JPEG/WebP/SVG renamed or not), or a corrupted/truncated PNG.

Common situations: Wrong working directory so relative paths don't resolve; the reference screenshot was never captured; the file was saved as JPEG but given a .png name; a partial download/transfer truncated the PNG.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of pbakaus/impeccable@2bc2879276 (2026-09-08). Data as JSON: /api/errors/4e28dc3be650ec8d. Report an issue: GitHub.

Appendix: source

Thrown at crates/comp-verbs/src/comp_diff.rs:698

    } else {
        io.cwd.join(path)
    }
}

// ---- CLI -------------------------------------------------------------------

/// `impeccable comp-diff --comp <png> --build <png> ...`
pub fn run(argv: &[String], io: &mut Io) -> i32 {
    let comp_path = arg(argv, "comp");
    let build_path = arg(argv, "build");
    let (Some(comp_path), Some(build_path)) = (comp_path, build_path) else {
        io.err("usage: comp-diff.mjs --comp <png> --build <png> [--spec spec.json] [--out-dir dir] [--align top|stretch] [--label name] [--threshold 0.75] [--json]\n");
        return 1;
    };
    let comp = match read_png(io, comp_path) {
        Ok(v) => v,
        Err(e) => {
            io.err(&format!("comp-diff: cannot read comp {comp_path}: {e}\n"));
            return 1;
        }
    };
    let build = match read_png(io, build_path) {
        Ok(v) => v,
        Err(e) => {
            io.err(&format!("comp-diff: cannot read build {build_path}: {e}\n"));
            return 1;
        }
    };
    let mut spec: Option<Value> = None;
    let spec_path = arg(argv, "spec");
    if let Some(sp) = spec_path {
        match std::fs::read_to_string(resolve(io, sp)) {
            Ok(raw) => match serde_json::from_str::<Value>(&raw) {
                Ok(v) => spec = Some(v),
                Err(e) => {
                    io.err(&format!("comp-diff: cannot read spec {sp}: {e}\n"));

View on GitHub (pinned to 2bc2879276)