{"record":{"id":"b8127e57b900a0d4","repo":"jesseduffield/lazygit","slug":"no-item-selected","errorCode":null,"errorMessage":"No item selected","messagePattern":"No item selected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/list_controller_trait.go","lineNumber":113,"sourceCode":"\t\t}\n\n\t\tfor _, callback := range callbacks {\n\t\t\tif reason := callback(items); reason != nil {\n\t\t\t\treturn reason\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\n// Passes the selected item to the callback. Used for handler functions.\nfunc (self *ListControllerTrait[T]) withItem(callback func(T) error) func() error {\n\treturn func() error {\n\t\tvar zeroValue T\n\t\tcommit := self.getSelectedItem()\n\t\tif commit == zeroValue {\n\t\t\treturn errors.New(self.c.Tr.NoItemSelected)\n\t\t}\n\n\t\treturn callback(commit)\n\t}\n}\n\nfunc (self *ListControllerTrait[T]) withItems(callback func([]T) error) func() error {\n\treturn func() error {\n\t\titems, _, _ := self.getSelectedItems()\n\t\tif len(items) == 0 {\n\t\t\treturn errors.New(self.c.Tr.NoItemSelected)\n\t\t}\n\n\t\treturn callback(items)\n\t}\n}\n\n// like withItems but also passes the start and end index of the selection","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/list_controller_trait.go#L95-L131","documentation":"Returned by ListControllerTrait.withItem when getSelectedItem() equals the zero value of T, meaning the list context has no selected row (empty list or no selection). It is the standard guard wrapping almost every per-item keybinding handler in lazygit's list views.","triggerScenarios":"Pressing a key whose handler was built via withItem(callback) while the focused list context is empty or has no highlighted row; e.g. deleting from an empty stash list or acting on an empty branches panel.","commonSituations":"Keybinding pressed the instant a view empties after a refresh (post-delete, post-checkout); custom keybindings bound to withItem-based handlers; empty repo states (no commits, no branches, no remotes).","solutions":["Populate the list first (e.g. create a commit/branch/remote) then retry the action.","Wait for the view refresh to finish after an operation that empties the list before pressing the next key.","For custom handlers, use withItemGraceful instead of withItem when the action should silently no-op on empty selection (as click handlers do)."],"exampleFix":"// before\nHandle: func() error { return self.withItem(self.delete)(nil) },\n\n// after (click-style actions that should no-op on empty space)\nHandle: func() error { return self.withItemGraceful(self.delete)(nil) },","handlingStrategy":"validation","validationCode":"if self.context().GetSelected() == nil { // or zero-value check for value types\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use withItem for keybindings (error is desirable) and withItemGraceful for mouse clicks (no-op desired).","Disable per-item keybindings via the controller's DisabledReason when the list can be empty.","After any refresh that can empty a list, move focus/selection to a valid context."],"tags":["ui","list-controller","selection","guard"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}