{"record":{"id":"e9343162fec7ea3d","repo":"gitbutlerapp/gitbutler","slug":"cannot-mix-mark-sources","errorCode":null,"errorMessage":"cannot mix mark sources","messagePattern":"cannot mix mark sources","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/status/tui/app/mark.rs","lineNumber":367,"sourceCode":"    }\n}\n\nimpl MarkStore<UncommittedHunkOrFile> for Marks {\n    type Error = anyhow::Error;\n\n    fn contains_mark(&self, mark: &UncommittedHunkOrFile) -> bool {\n        self.as_hunks()\n            .is_some_and(|hunks| hunks.iter().any(|hunk| hunk == mark))\n    }\n\n    fn insert_mark(&mut self, mark: UncommittedHunkOrFile) -> Result<(), Self::Error> {\n        if self.contains_mark(&mark) {\n            return Ok(());\n        }\n        match self {\n            Self::Empty => *self = Self::Hunks(NonEmpty::new(mark)),\n            Self::Hunks(hunks) => hunks.push(mark),\n            _ => anyhow::bail!(\"cannot mix mark sources\"),\n        }\n        Ok(())\n    }\n\n    fn remove_mark(&mut self, mark: &UncommittedHunkOrFile) {\n        let Self::Hunks(hunks) = self else {\n            return;\n        };\n\n        if remove_from_non_empty(hunks, |marked| marked == mark) {\n            *self = Self::Empty;\n        }\n    }\n}\n\nimpl MarkStore<CommitId> for Marks {\n    type Error = anyhow::Error;\n","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/status/tui/app/mark.rs#L349-L385","documentation":"The TUI status `Marks` enum is a single-variant-of-each state machine: it can hold marks of exactly one source kind (hunks/files vs commits vs committed files). `insert_mark` for `UncommittedHunkOrFile` only supports `Empty` and `Hunks`; any other variant is a state-machine violation and bails with 'cannot mix mark sources'.","triggerScenarios":"Inserting an uncommitted hunk/file mark while the marks state currently holds `Commits` or `CommittedFiles` — i.e. the user (or a TUI keybinding) marks a commit, then attempts to mark a working-tree hunk/file without clearing first.","commonSituations":"In the `but` TUI: selecting commits in one pane, then marking hunks/files from the uncommitted-changes pane; a keyboard shortcut or mouse path that skips the implicit clear of prior marks.","solutions":["Clear the current marks (unmark / press the clear-marks key) before marking items of a different source kind.","Mark only items from one source (uncommitted hunks/files OR commits OR committed files) per apply operation.","If this fires from a keybinding path, fix the caller to call `remove_mark`/clear before switching mark domains."],"exampleFix":"// before: app code inserting without clearing\nmarks.insert_hunk_or_file(hunk)?; // marks currently Commits -> bail\n// after\nif !matches!(marks, Marks::Empty | Marks::Hunks(_)) {\n    marks = Marks::Empty;\n}\nmarks.insert_hunk_or_file(hunk)?;","handlingStrategy":"try-catch","validationCode":"fn can_insert_hunk_or_file(marks: &Marks) -> bool {\n    matches!(marks, Marks::Empty | Marks::Hunks(_))\n}","typeGuard":"fn is_hunk_or_file_state(m: &Marks) -> bool {\n    matches!(m, Marks::Empty | Marks::Hunks(_))\n}","tryCatchPattern":"if let Err(e) = marks.insert_hunk_or_file(mark) {\n    if e.to_string().contains(\"cannot mix mark sources\") {\n        marks = Marks::Empty;\n        marks.insert_hunk_or_file(mark)?;\n    } else { return Err(e); }\n}","preventionTips":["Clear the mark set whenever the TUI focus moves between source panes","Only one mark source per apply operation","Add a UI-level guard that unmarks before switching domains"],"tags":["tui","state-machine","invalid-state","marks"],"backgroundTag":"invalid-state-transition","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"}