gitbutlerapp/gitbutler · error

no illformed UTF8

Error message

no illformed UTF8

What it means

After writing the signature into memory, serialize_line converts the bytes to &str with std::str::from_utf8 and panics on invalid UTF-8. Git signatures are specified to be UTF-8 (name/email and a timestamp), so ill-formed bytes indicate corrupted reflog data.

Solutions

  1. Inspect the reflog file with a hex editor to find the non-UTF-8 bytes in the committer name and fix or remove the line.
  2. Sanitize the bytes before conversion (e.g. String::from_utf8_lossy) if lossy output is acceptable for display.
  3. Propagate the error instead of panicking: return anyhow::Result<String> and report the offending reflog line to the user.
  4. If the repo came from a third-party tool, re-clone or rewrite the reflog to normalize the signature.

Example fix

// before
std::str::from_utf8(&sig).expect("no illformed UTF8"),
// after
String::from_utf8_lossy(&sig),
Defensive patterns

Strategy: validation

Validate before calling

// Validate the reflog line bytes decode as UTF-8 before serializing
if std::str::from_utf8(&sig).is_err() {
    eprintln!("reflog line has non-UTF-8 signature, skipping/lossy-decoding");
}

Try / catch

// Use lossy conversion or propagate instead of panicking
let sig_str = String::from_utf8_lossy(&sig);
// or: std::str::from_utf8(&sig).map_err(|e| anyhow!("reflog signature not UTF-8: {e}"))?

Prevention

When it happens

Trigger: Called by build_reflog_content for each reflog line; fires only when the serialized signature bytes are not valid UTF-8, i.e. the reflog file contains non-UTF-8 committer data.

Common situations: Hand-edited or corrupted .git/logs files; reflogs copied from a filesystem with different encoding; repos created by non-conforming git tooling that wrote raw bytes into the committer name.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/702f16f1cfbe92e5. Report an issue: GitHub.

Appendix: source

Thrown at crates/gitbutler-oplog/src/reflog.rs:158

        log.push_str(&serialize_line(reflog_line));
        log.push('\n');
    }

    log
}

fn serialize_line(line: gix::refs::file::log::LineRef<'_>) -> String {
    let mut sig = Vec::new();
    line.signature
        .write_to(&mut sig)
        .expect("write to memory succeeds");

    format!(
        "{} {} {}\t{}",
        line.previous_oid,
        line.new_oid,
        std::str::from_utf8(&sig).expect("no illformed UTF8"),
        line.message
    )
}

#[cfg(test)]
mod set_target_ref {
    use std::str::FromStr;

    use but_testsupport::{CommandExt, git_at_dir};
    use gix::refs::file::log::LineRef;
    use pretty_assertions::assert_eq;
    use tempfile::tempdir;

    use super::{
        GITBUTLER_COMMIT_AUTHOR_EMAIL, GITBUTLER_COMMIT_AUTHOR_NAME, ReflogCommits,
        set_reference_to_oplog,
    };

View on GitHub (pinned to 58e5313667)