aaif-goose/goose · error

git diff returned non-UTF8 output: {e}

Error message

git diff returned non-UTF8 output: {e}

What it means

The review command shells out to `git diff` and requires its stdout to be valid UTF-8 (String::from_utf8 on out.stdout). Repos whose diff output contains non-UTF8 bytes — typically filenames in legacy encodings or binary content leaking into hunks — fail the conversion and abort diff collection.

Source

Thrown at crates/goose-cli/src/commands/review/handler.rs:419

    match range {
        Some(r) => {
            cmd.arg(r);
        }
        None => {
            cmd.arg("HEAD");
        }
    }
    if !files.is_empty() {
        cmd.arg("--");
        for f in files {
            cmd.arg(f);
        }
    }
    let out = cmd.output().context("git diff failed")?;
    if !out.status.success() {
        bail!("git diff failed: {}", String::from_utf8_lossy(&out.stderr));
    }
    String::from_utf8(out.stdout).map_err(|e| anyhow!("git diff returned non-UTF8 output: {e}"))
}

fn collect_diff_stat(repo_root: &Path, range: Option<&str>, files: &[String]) -> Result<String> {
    let mut cmd = review_git_command(repo_root);
    cmd.arg("diff").arg("--stat");
    match range {
        Some(r) => {
            cmd.arg(r);
        }
        None => {
            cmd.arg("HEAD");
        }
    }
    if !files.is_empty() {
        cmd.arg("--");
        for f in files {
            cmd.arg(f);
        }

View on GitHub (pinned to 3810898a74)

Solutions

  1. Scope the review to known text paths: `goose review --files 'src/**'`
  2. Set `git config core.quotepath true` so git escapes non-ASCII path bytes in output
  3. Rename offending files to valid UTF-8 names
  4. Mark binaries in .gitattributes (e.g. `*.bin binary`) so git omits their content from diffs

Example fix

# before
goose review                    # non-UTF8 filename in diff -> error

# after
git config core.quotepath true
goose review --files 'src/**/*.rs'
Defensive patterns

Strategy: validation

Validate before calling

# Pre-check that the diff decodes as UTF-8 before reviewing
git diff HEAD | iconv -f UTF-8 -t UTF-8 > /dev/null 2>&1 \
  || echo 'git diff output is not valid UTF-8: fix filenames or set core.quotepath=true'

Try / catch

// Rust (own tooling): accept lossy decoding when output is display-only
let diff = String::from_utf8_lossy(&out.stdout).into_owned();

Prevention

When it happens

Trigger: Running `goose review` on a repo where the diff includes files whose names contain non-UTF8 bytes (e.g. latin-1 encoded paths) or binary blobs whose raw bytes appear in the diff output.

Common situations: Repos with legacy filename encodings; accidental binary commits; cross-platform checkouts on macOS/Windows producing oddly named files; unquoted non-ASCII paths in git output.

Related errors


AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16). Data as JSON: /api/errors/9ef716c09997e24f. Report an issue: GitHub.