{"record":{"id":"03304469b0212602","repo":"gitbutlerapp/gitbutler","slug":"could-not-find-associated-reference-name","errorCode":null,"errorMessage":"Could not find associated reference name","messagePattern":"Could not find associated reference name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-action/src/simple.rs","lineNumber":113,"sourceCode":"    } else {\n        change_summary.to_string()\n    };\n\n    for (stack_id, diff_specs) in stack_assignments {\n        if diff_specs.is_empty() {\n            continue;\n        }\n        if let Some(exclusive_stack) = exclusive_stack\n            && exclusive_stack != stack_id\n        {\n            continue; // Skip stacks that are not the exclusive stack.\n        }\n\n        let stack_branch_name = stacks\n            .iter()\n            .find(|s| s.id == stack_id)\n            .map(|s| s.branch_name.clone())\n            .ok_or(anyhow!(\"Could not find associated reference name\"))?;\n        let full_ref_name: gix::refs::FullName =\n            format!(\"refs/heads/{stack_branch_name}\").try_into()?;\n\n        let editor = Editor::create(ws, meta, repo, db)?;\n        let outcome = but_workspace::commit::commit_create(\n            editor,\n            diff_specs,\n            RelativeToRef::Reference(full_ref_name.as_ref()),\n            InsertSide::Below,\n            &commit_message,\n            context_lines,\n            but_workspace::commit::ChangeSource::Head,\n        )?;\n\n        if !outcome.rejected_specs.is_empty() {\n            tracing::warn!(\n                ?outcome.rejected_specs,\n                \"Failed to commit at least one hunk\"","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-action/src/simple.rs#L95-L131","documentation":"In `but-action`'s handle_changes flow, the code looks up the stack whose id matches `stack_id` in the workspace's stack list in order to derive its branch name (which becomes `refs/heads/<name>` for committing). If no stack in the workspace has that id, this anyhow error is thrown. It is a lookup failure: the caller supplied a stack id (or the workspace state contains a stack id) that does not resolve to an existing stack entry.","triggerScenarios":"Calling the handle_changes action with a `stack_id` that is absent from `stacks` (e.g. a stale StackId captured before the stack was unapplied, deleted, or after the workspace was rebuilt); internal callers passing an id from outdated workspace metadata.","commonSituations":"UI or script cached a stack id from a previous operation; the stack was unapplied/removed between listing and committing; operating on a different workspace snapshot than the one the id came from.","solutions":["Refresh the workspace stack list and re-resolve the stack id before calling the action.","Verify the stack is currently applied/in the workspace (not unapplied or deleted) using `but` workspace status.","Pass the correct stack id — pick it from the current workspace output rather than a cached value.","If the id comes from an event/callback, re-validate it against the live workspace before use."],"exampleFix":"// before\nlet stack_id = cached_stack_id;\nhandle_changes(..., stack_id, ...);\n// after\nlet stacks = workspace.stacks(); // re-read current state\nlet stack_id = stacks.iter().find(|s| s.branch_name == \"my-branch\").map(|s| s.id)\n    .ok_or_else(|| anyhow::anyhow!(\"branch my-branch is not applied in the workspace\"))?;\nhandle_changes(..., stack_id, ...);","handlingStrategy":"validation","validationCode":"// Rust: verify the stack id resolves in the current workspace before calling\nlet stack = workspace.stacks.iter().find(|s| s.id == stack_id)\n    .ok_or_else(|| anyhow::anyhow!(\"stack {stack_id:?} is not in the current workspace\"))?;","typeGuard":"fn stack_exists(stacks: &[Stack], id: StackId) -> bool { stacks.iter().any(|s| s.id == Some(id)) }","tryCatchPattern":"match handle_changes(...) {\n    Err(e) if e.to_string().contains(\"Could not find associated reference name\") => {\n        refresh_workspace()?; // stale id — retry once with fresh state\n    }\n    other => other?,\n}","preventionTips":["Always resolve stack ids from a freshly read workspace, never from cached state","Re-validate ids received from UI events against live workspace state","Check stack applied-status before mutating operations"],"tags":["git","workspace","stack-not-found","rust"],"backgroundTag":"resource-not-found","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"}