gitbutlerapp/gitbutler · error
Invalid stage ' ' for
Error message
Invalid stage '{other}' for '{rela_path}' What it means
Internal consistency check while reconstructing unmerged index entries: each conflicted record's path is expected to end in /<stage> with a numeric stage of 1, 2, or 3 (ours/base/theirs). A parsed stage outside that set means the index holds an unexpected stage number for the path - effectively a bug guard over malformed or unusual index data rather than user input.
Solutions
- Rebuild the snapshot from current repository state to drop the invalid stage entries
- Fix the writer that produced out-of-range stage numbers
- Validate stage numbers when constructing snapshot conflict entries
Defensive patterns
Strategy: validation
Validate before calling
let stage = parse_stage(suffix)?; // must be 1..=3 before encoding into the snapshot tree
if !(1..=3).contains(&stage) { return Err(anyhow!("stage {stage} out of range")); } Prevention
- Validate stage numbers at snapshot-write time, not only at read time
- Never pass through stage numbers from untrusted data
- Constrain the stage type so out-of-range values are unrepresentable
When it happens
Trigger: Resolving an 'index-conflicts' tree containing an entry whose path suffix parses to a stage number outside 1..=3 (e.g. 'file.txt/4' or 'file.txt/99').
Common situations: Corrupted snapshot trees; third-party tools writing conflict entries; buggy snapshot writers encoding stage numbers incorrectly.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Unconflicted stage for
- Cannot reconcile : branch name ' ' occurs more than once
- Snapshot tree needs a 'HEAD' entry if it has only a…
- stale pre-commit index backup at
- Aborting due to empty branch name
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/c41672af2c9bdf3d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-core/src/snapshot/resolve_tree.rs:165
for record in &recorder.records {
if record.mode.is_tree() {
continue;
}
let rela_path = &record.filepath;
let rslash_pos = rela_path
.rfind("/")
.context("BUG: expecting <path>/<stage>")?;
let stage: usize = rela_path[rslash_pos + 1..]
.to_str()?
.parse()
.context("Failed to parse stage that should only be [1,2,3]")?;
let rela_path = rela_path[..rslash_pos].as_bstr();
let stage = match stage {
0 => bail!("Unconflicted stage for '{rela_path}' is unexpected"),
1 => Stage::Base,
2 => Stage::Ours,
3 => Stage::Theirs,
other => bail!("Invalid stage '{other}' for '{rela_path}'"),
};
index.dangerously_push_entry(
Default::default(),
record.oid,
Flags::from_stage(stage),
record.mode.into(),
rela_path,
);
to_remove.insert(rela_path);
}
index.remove_entries(|_idx, path, entry| {
entry.flags.stage() == Stage::Unconflicted && to_remove.contains(path)
});
index.sort_entries();
Ok(())View on GitHub (pinned to 58e5313667)