{"record":{"id":"5cc103df3d7c8733","repo":"gitbutlerapp/gitbutler","slug":"expected-selector-for-step-to-refer-to-a-reference","errorCode":null,"errorMessage":"Expected selector for {step:?} to refer to a reference","messagePattern":"Expected selector for (.+?) to refer to a reference","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/mod.rs","lineNumber":233,"sourceCode":"\nimpl ToCommitSelector for Selector {\n    fn to_commit_selector(&self, editor: &Editor<impl RefMetadata>) -> Result<Selector> {\n        let selector = editor.history.normalize_selector(*self)?;\n        let step = &editor.graph[selector.id];\n        if !matches!(step, Step::Pick(_)) {\n            bail!(\"Expected selector for {step:?} to refer to a commit\");\n        }\n\n        Ok(selector)\n    }\n}\n\nimpl ToReferenceSelector for Selector {\n    fn to_reference_selector(&self, editor: &Editor<impl RefMetadata>) -> Result<Selector> {\n        let selector = editor.history.normalize_selector(*self)?;\n        let step = &editor.graph[selector.id];\n        if !matches!(step, Step::Reference { .. }) {\n            bail!(\"Expected selector for {step:?} to refer to a reference\");\n        }\n\n        Ok(selector)\n    }\n}\n\nimpl ToSelector for Selector {\n    fn to_selector(&self, _: &Editor<impl RefMetadata>) -> Result<Selector> {\n        Ok(*self)\n    }\n}\n\n/// Represents places where `safe_checkout` should be called from\n#[derive(Debug, Clone)]\npub(crate) enum Checkout {\n    /// The HEAD of the `repo` the editor was created for.\n    Head {\n        selector: Selector,","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/graph_rebase/mod.rs#L215-L251","documentation":"ToReferenceSelector::to_reference_selector normalizes a Selector and asserts the graph node is a Step::Reference (a named ref such as a branch). If it resolves to any other step kind (e.g. a Pick/commit), the conversion is invalid and the library bails.","triggerScenarios":"Calling to_reference_selector with a Selector that normalizes to a non-Reference step — e.g. passing a commit-pick selector into a move-branch/rename-reference API, or a stale selector that re-resolves to a Pick after graph edits.","commonSituations":"Confusing commit selectors with branch selectors when scripting rebase graph mutations; calling branch operations on commit ids; selectors invalidated by earlier mutations to the editor graph.","solutions":["Verify editor.graph[selector.id] is a Step::Reference before the call","Use to_commit_selector if the selector targets a commit","Re-derive the selector from the current editor/graph state"],"exampleFix":"// before: selector points at a commit -> error\nlet refname = selector.to_reference_selector(&editor)?;\n// after\nlet step = &editor.graph[selector.id];\nlet refname = match step {\n    Step::Reference { .. } => selector.to_reference_selector(&editor)?,\n    Step::Pick(_) => bail!(\"use a reference selector here\"),\n    _ => bail!(\"unsupported step\"),\n};","handlingStrategy":"type-guard","validationCode":"let step = &editor.graph[selector.id];\nif !matches!(step, Step::Reference { .. }) { return Err(anyhow!(\"not a reference selector\")); }","typeGuard":"fn is_reference(selector: Selector, editor: &Editor<impl RefMetadata>) -> bool {\n    matches!(editor.graph[selector.id], Step::Reference { .. })\n}","tryCatchPattern":"match selector.to_reference_selector(&editor) {\n    Ok(r) => r,\n    Err(_) => bail!(\"selector does not refer to a reference; check step kind first\"),\n}","preventionTips":["Keep commit and reference selectors in separate typed variables","Re-derive selectors from the editor after mutations"],"tags":["rebase","selector","type-mismatch"],"backgroundTag":"type-mismatch","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"}