charmbracelet/gum · error
failed to run write: %w
Error message
failed to run write: %w
What it means
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.
Source
Thrown at write/command.go:79
help: help.New(),
showHelp: o.ShowHelp,
keymap: defaultKeymap(),
padding: []int{top, right, bottom, left},
}
m.textarea.KeyMap.InsertNewline = m.keymap.InsertNewline
ctx, cancel := timeout.Context(o.Timeout)
defer cancel()
p := tea.NewProgram(
m,
tea.WithOutput(os.Stderr),
tea.WithContext(ctx),
)
tm, err := p.Run()
if err != nil {
return fmt.Errorf("failed to run write: %w", err)
}
m = tm.(model)
if !m.submitted {
return errors.New("not submitted")
}
fmt.Println(m.textarea.Value())
return nil
}
View on GitHub (pinned to 4d089f9550)
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
Example fix
// before nohup ./script-using-gum-write.sh & # no TTY → fails // after if [ -t 0 ]; then text=$(gum write); else read -r text; fi
Defensive patterns
Strategy: try-catch
Validate before calling
[ -t 0 ] && [ -t 2 ] || { echo 'gum write requires an interactive terminal'; exit 1; } Try / catch
if ! text=$(gum write 2>/dev/null); then echo 'write cancelled or TUI failed' >&2 exit 1 fi
Prevention
- Run gum write only in TTY-capable sessions
- Add non-TTY fallbacks in scripts (plain read)
- Check context cancellation before invoking interactive commands
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- unable to start program: %w
- failed to start tea program: %w
- unable to run filter: %w
- unable to run action: %w
- failed to get selection
AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31).
Data as JSON: /api/errors/af533e136bae8c58.
Report an issue: GitHub.