{"record":{"id":"97a0398d508ee826","repo":"gitbutlerapp/gitbutler","slug":"no-stacks-found-in-the-workspace","errorCode":null,"errorMessage":"No stacks found in the workspace","messagePattern":"No stacks found in the workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-action/src/simple.rs","lineNumber":70,"sourceCode":"        context_lines,\n    )\n    .map_err(|err| serde_error::Error::new(&*err))?;\n    if assignments.is_empty() {\n        return Ok(Outcome {\n            updated_branches: vec![],\n        });\n    }\n\n    // Get the current stacks in the workspace, creating one if none exists.\n    let stacks = stacks_creating_if_none(repo, ws, meta, perm)?;\n\n    // Put the assignments into buckets by stack ID.\n    let mut stack_assignments: HashMap<StackId, Vec<DiffSpec>> =\n        stacks.iter().map(|s| (s.id, vec![])).collect();\n    let default_stack_id = stacks\n        .first()\n        .map(|s| s.id)\n        .ok_or_else(|| anyhow::anyhow!(\"No stacks found in the workspace\"))?;\n    for assignment in assignments {\n        if let Some(stack_id) = assignment.stack_id {\n            stack_assignments\n                .entry(stack_id)\n                .or_default()\n                .push(assignment.into());\n        } else if exclusive_stack.is_none() {\n            // If there is an exclusive stack. We don't want to do anything with\n            // the unassigned changes.\n            stack_assignments\n                .entry(default_stack_id)\n                .or_default()\n                .push(assignment.into());\n        }\n    }\n    // Go over the stack_assignments and flatten the diff specs for each stack.\n    for (_, specs) in stack_assignments.iter_mut() {\n        *specs = but_workspace::flatten_diff_specs(specs.clone());","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-action/src/simple.rs#L52-L88","documentation":"handle_changes buckets incoming file assignments by stack ID and needs a default stack (the first stack in the workspace) for assignments that do not name one. If the workspace contains no stacks at all, there is nothing to assign files to and no default to fall back on, so this error is thrown.","triggerScenarios":"Calling handle_changes when the computed workspace stack list is empty — the workspace has no applied branches/stacks (everything merged/cleaned up, or workspace state is empty) while file assignments are being submitted.","commonSituations":"Running `but` file-assignment commands in a repo where the GitButler workspace was just cleaned (all stacks merged); automations firing against an empty workspace; a state desync where workspace loading returned no stacks despite UI showing one.","solutions":["Create a stack/branch in the workspace first (e.g. `but branch create` or via the UI), then retry handling changes.","Verify the workspace actually has stacks (`but` workspace/status output) before submitting assignments.","If stacks should exist but do not, refresh/reload workspace state to fix a potential desync."],"exampleFix":"// before\nhandle_changes(ctx, assignments, opts)?; // Err: No stacks found in the workspace\n\n// after\nlet stacks = but_workspace::stacks(ctx)?;\nif stacks.is_empty() {\n    create_stack(ctx, \"my-branch\")?;\n}\nhandle_changes(ctx, assignments, opts)?;","handlingStrategy":"validation","validationCode":"let stacks = but_workspace::stacks(ctx)?;\nif stacks.is_empty() {\n    anyhow::bail!(\"create a stack before assigning changes\");\n}","typeGuard":null,"tryCatchPattern":"match handle_changes(ctx, assignments, opts) {\n    Err(e) if e.to_string().contains(\"No stacks found in the workspace\") => {\n        // create a branch/stack first, then retry\n    }\n    other => other?,\n}","preventionTips":["Check workspace status for at least one stack before submitting file assignments.","Create a branch/stack as the first step of automation scripts against a fresh workspace.","Reload workspace state after merges/cleanups so stale stacks do not mask an empty workspace."],"tags":["workspace","stacks","empty-state","assignment"],"backgroundTag":"empty-result-set","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"}