{"record":{"id":"c41672af2c9bdf3d","repo":"gitbutlerapp/gitbutler","slug":"invalid-stage-other-for-rela-path","errorCode":null,"errorMessage":"Invalid stage '{other}' for '{rela_path}'","messagePattern":"Invalid stage '(.+?)' for '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/snapshot/resolve_tree.rs","lineNumber":165,"sourceCode":"        for record in &recorder.records {\n            if record.mode.is_tree() {\n                continue;\n            }\n            let rela_path = &record.filepath;\n            let rslash_pos = rela_path\n                .rfind(\"/\")\n                .context(\"BUG: expecting <path>/<stage>\")?;\n            let stage: usize = rela_path[rslash_pos + 1..]\n                .to_str()?\n                .parse()\n                .context(\"Failed to parse stage that should only be [1,2,3]\")?;\n            let rela_path = rela_path[..rslash_pos].as_bstr();\n            let stage = match stage {\n                0 => bail!(\"Unconflicted stage for '{rela_path}' is unexpected\"),\n                1 => Stage::Base,\n                2 => Stage::Ours,\n                3 => Stage::Theirs,\n                other => bail!(\"Invalid stage '{other}' for '{rela_path}'\"),\n            };\n\n            index.dangerously_push_entry(\n                Default::default(),\n                record.oid,\n                Flags::from_stage(stage),\n                record.mode.into(),\n                rela_path,\n            );\n\n            to_remove.insert(rela_path);\n        }\n        index.remove_entries(|_idx, path, entry| {\n            entry.flags.stage() == Stage::Unconflicted && to_remove.contains(path)\n        });\n\n        index.sort_entries();\n        Ok(())","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/snapshot/resolve_tree.rs#L147-L183","documentation":"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.","triggerScenarios":"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').","commonSituations":"Corrupted snapshot trees; third-party tools writing conflict entries; buggy snapshot writers encoding stage numbers incorrectly.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let stage = parse_stage(suffix)?; // must be 1..=3 before encoding into the snapshot tree\nif !(1..=3).contains(&stage) { return Err(anyhow!(\"stage {stage} out of range\")); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","git","index","conflict","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}