{"record":{"id":"af533e136bae8c58","repo":"charmbracelet/gum","slug":"failed-to-run-write-w","errorCode":null,"errorMessage":"failed to run write: %w","messagePattern":"failed to run write: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"write/command.go","lineNumber":79,"sourceCode":"\t\thelp:        help.New(),\n\t\tshowHelp:    o.ShowHelp,\n\t\tkeymap:      defaultKeymap(),\n\t\tpadding:     []int{top, right, bottom, left},\n\t}\n\n\tm.textarea.KeyMap.InsertNewline = m.keymap.InsertNewline\n\n\tctx, cancel := timeout.Context(o.Timeout)\n\tdefer cancel()\n\n\tp := tea.NewProgram(\n\t\tm,\n\t\ttea.WithOutput(os.Stderr),\n\t\ttea.WithContext(ctx),\n\t)\n\ttm, err := p.Run()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to run write: %w\", err)\n\t}\n\tm = tm.(model)\n\tif !m.submitted {\n\t\treturn errors.New(\"not submitted\")\n\t}\n\tfmt.Println(m.textarea.Value())\n\treturn nil\n}\n","sourceCodeStart":61,"sourceCodeEnd":88,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/write/command.go#L61-L88","documentation":"gum write could not run its Bubble Tea program (the interactive textarea). The underlying tea error is wrapped with %w. Without the TUI, the text input cannot be collected, so the command aborts.","triggerScenarios":"`p.Run()` on the tea program returns an error: no TTY, context cancelled before/during run, output initialization to os.Stderr fails, or terminal capability issues.","commonSituations":"Running `gum write` in CI or non-interactive scripts, cancelling via Ctrl-C combined with context propagation, detached sessions (cron, nohup) with no terminal attached.","solutions":["Run gum write in an interactive terminal","Verify the calling context isn't cancelled before the program runs","Use `gum write --placeholder ...` only in TTY-capable environments; fall back to plain read for non-TTY","Inspect the wrapped %w cause to identify the specific tea failure"],"exampleFix":"// before\nnohup ./script-using-gum-write.sh &   # no TTY → fails\n// after\nif [ -t 0 ]; then text=$(gum write); else read -r text; fi","handlingStrategy":"try-catch","validationCode":"[ -t 0 ] && [ -t 2 ] || { echo 'gum write requires an interactive terminal'; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! text=$(gum write 2>/dev/null); then\n  echo 'write cancelled or TUI failed' >&2\n  exit 1\nfi","preventionTips":["Run gum write only in TTY-capable sessions","Add non-TTY fallbacks in scripts (plain read)","Check context cancellation before invoking interactive commands"],"tags":["tui","terminal","bubbletea"],"backgroundTag":"tui-program-start-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}