{"record":{"id":"f9edbea25a62314d","repo":"charmbracelet/gum","slug":"unable-to-run-filter-w","errorCode":null,"errorMessage":"unable to run filter: %w","messagePattern":"unable to run filter: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"filter/command.go","lineNumber":148,"sourceCode":"\tcurrentSelected := 0\n\tif len(o.Selected) > 0 {\n\t\tfor i, option := range matches {\n\t\t\tif currentSelected >= o.Limit || (!isSelectAll && !slices.Contains(o.Selected, option.Str)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif o.Limit == 1 {\n\t\t\t\tm.cursor = i\n\t\t\t\tm.selected[option.Str] = struct{}{}\n\t\t\t} else {\n\t\t\t\tcurrentSelected++\n\t\t\t\tm.selected[option.Str] = struct{}{}\n\t\t\t}\n\t\t}\n\t}\n\n\ttm, err := tea.NewProgram(m, options...).Run()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to run filter: %w\", err)\n\t}\n\n\tm = tm.(model)\n\tif !m.submitted {\n\t\treturn errors.New(\"nothing selected\")\n\t}\n\n\t// allSelections contains values only if limit is greater\n\t// than 1 or if flag --no-limit is passed, hence there is\n\t// no need to further checks\n\tif len(m.selected) > 0 {\n\t\to.checkSelected(m)\n\t} else if len(m.matches) > m.cursor && m.cursor >= 0 {\n\t\ttty.Println(m.matches[m.cursor].Str)\n\t}\n\n\treturn nil\n}","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/filter/command.go#L130-L166","documentation":"gum filter wraps the Bubble Tea program loop for its interactive fuzzy-filter picker. If `tea.NewProgram(...).Run()` returns an error (renderer/TTY failure, context cancellation, I/O error writing to the output), Run returns it wrapped with `unable to run filter: %w`. This means the interactive UI never completed, not that the user failed to pick an item (that is the separate \"nothing selected\" error).","triggerScenarios":"Running `gum filter` when stdout/stderr is not a TTY (piped/captured output without a pty), a context passed to the program is cancelled before the user selects, or the Bubble Tea program fails to start its input/output renderer.","commonSituations":"CI pipelines or scripts that capture gum output through pipes; automation that sets a short context deadline and cancels while the filter is open; terminal emulators or environments where gum cannot detect terminal size.","solutions":["Run gum from a real terminal or wrap it in a pty (e.g. `script -qec 'gum filter ...' /dev/null`) when piping output.","Check the wrapped error (`errors.Unwrap` / `%v`) to see whether the context was cancelled and extend or remove the deadline.","If no TTY is available, avoid interactive filtering and use non-interactive alternatives (grep/fzf --filter, or a pre-computed selection).","Update gum/Bubble Tea to the latest versions — older releases had TTY-detection bugs in non-interactive environments."],"exampleFix":"// before\ncmd := exec.Command(\"gum\", \"filter\", \"one\", \"two\")\nout, err := cmd.Output() // fails in non-TTY environment\n// after\ncmd := exec.Command(\"script\", \"-qec\", \"gum filter one two\", \"/dev/null\")\nout, err := cmd.Output() // allocate a pty so the TUI can run","handlingStrategy":"fallback","validationCode":"if [ -t 0 ] && [ -t 1 ]; then\n  selection=$(gum filter \"${items[@]}\")\nelse\n  echo \"interactive TTY required; using first item\" >&2\n  selection=\"${items[0]}\"\nfi","typeGuard":null,"tryCatchPattern":"if ! selection=$(gum filter \"${items[@]}\"); then\n  echo \"filter failed: $selection\" >&2\n  selection=\"${items[0]}\" # fallback\nfi","preventionTips":["Only invoke gum filter when stdin/stdout are TTYs ([ -t 0 ] && [ -t 1 ]).","Use a pty wrapper (script/unbuffer/expect) in scripts and CI.","Set generous context deadlines when driving gum programmatically.","Keep gum and Bubble Tea updated for TTY-detection fixes."],"tags":["go","cli","tui","bubbletea"],"backgroundTag":"tui-program-run-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}