gitbutlerapp/gitbutler · error

Could not resolve stack

Error message

Could not resolve stack '{stack}' by UUID or workspace branch name

What it means

resolve_stack_id in the debug API could not match the user-supplied stack identifier against any stack in the current workspace. The identifier is matched by stack UUID or by workspace branch name; when the filter-map yields no matching stack id, the function bails with this message.

Solutions

  1. List the current workspace stacks (e.g. `but debug workspace` equivalent) and copy the exact UUID or branch name
  2. Retry with the short workspace branch name instead of a full ref or a local-only nickname
  3. Verify the stack is still applied; if it was unapplied or archived, it will not resolve
  4. If the stack exists in another worktree/workspace, switch to the workspace that contains it

Example fix

// before
let id = api.resolve_stack_id(&mut ws, "my-branch")?; // typo: branch is "my_branch"
// after
let id = api.resolve_stack_id(&mut ws, "my_branch")?; // exact UUID or workspace branch name
Defensive patterns

Strategy: validation

Validate before calling

let known: Vec<_> = workspace.stacks.iter()
    .filter_map(|s| s.id.as_ref().map(|i| i.to_string()))
    .chain(workspace.stacks.iter().filter_map(|s| s.branch_name()))
    .collect();
if !known.iter().any(|k| k == stack) { eprintln!("unknown stack: {stack}"); }

Try / catch

match api.resolve_stack_id(&mut ws, stack) {
    Err(e) if e.to_string().contains("Could not resolve stack") => eprintln!("use `but debug workspace` to list valid stack ids"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling resolve_stack_id (e.g. via unapply_stack) with a `stack` argument that is neither a valid stack UUID present in workspace.stacks nor the name of a workspace branch of any stack in the workspace.

Common situations: Typo in the stack name or UUID, the stack was already unapplied/archived so it no longer appears in workspace.stacks, or the user passed a full branch ref name (e.g. refs/heads/foo) instead of the short branch name.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-debug/src/command/api.rs:85

    fn stack_matches(stack: &but_graph::workspace::Stack, name: &str) -> bool {
        stack.segments.iter().any(|segment| {
            segment.ref_name().is_some_and(|ref_name| {
                ref_name == name || ref_name.shorten().as_bstr() == name.as_bytes()
            })
        })
    }
    if let Ok(stack_id) = stack.parse::<StackId>() {
        return Ok(stack_id);
    }

    let (_guard, _repo, workspace, _db) = ctx.workspace_and_db()?;
    let mut matches = workspace.stacks.iter().filter_map(|workspace_stack| {
        stack_matches(workspace_stack, stack)
            .then_some(workspace_stack.id)
            .flatten()
    });
    let Some(stack_id) = matches.next() else {
        bail!("Could not resolve stack '{stack}' by UUID or workspace branch name");
    };
    if matches.next().is_some() {
        bail!("Stack name '{stack}' is ambiguous in the current workspace");
    }
    Ok(stack_id)
}

View on GitHub (pinned to 58e5313667)