charmbracelet/gum · error

failed to run input: %w

Error message

failed to run input: %w

What it means

gum input runs a Bubble Tea program (with output on stderr and the caller's context). If `p.Run()` itself fails — the context is cancelled/deadline exceeded, the terminal cannot be initialized, or writing output fails — Run wraps it as `failed to run input: %w`. Unlike "not submitted", the prompt never ran to completion at all.

Source

Thrown at input/command.go:72

		headerStyle: o.HeaderStyle.ToLipgloss(),
		padding:     []int{top, right, bottom, left},
		autoWidth:   o.Width < 1,
		showHelp:    o.ShowHelp,
		help:        help.New(),
		keymap:      defaultKeymap(),
	}

	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 input: %w", err)
	}

	m = tm.(model)
	if !m.submitted {
		return errors.New("not submitted")
	}
	fmt.Println(m.textinput.Value())
	return nil
}

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Inspect the wrapped cause: if it is `context.DeadlineExceeded`, increase the timeout or remove the deadline.
  2. Run in a real terminal or allocate a pty when invoked from scripts/CI.
  3. Pass a context that lives as long as the user interaction should, not one tied to a short request.
  4. Check TERM and terminal capabilities; force a known TERM value in constrained environments.

Example fix

// before
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
m, err := input.Run(...) // fails: failed to run input: context deadline exceeded
// after
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) // allow time for user input
defer cancel()
Defensive patterns

Strategy: validation

Validate before calling

[ -t 0 ] && [ -t 1 ] || { echo "gum input needs a TTY" >&2; exit 1; }

Try / catch

if ! value=$(timeout 300 gum input); then
  echo "failed to run input (timeout or TTY issue)" >&2
fi

Prevention

When it happens

Trigger: The context passed via `tea.WithContext(ctx)` is cancelled or exceeds its deadline while the prompt is open; stdin/stdout/stderr are not a usable TTY; terminal setup (raw mode, size query) fails.

Common situations: Timeouts wrapping gum invocations (e.g. `timeout 5 gum input ...`) killing the prompt; non-interactive CI environments lacking a pty; embedded Go callers cancelling the context programmatically.

Related errors


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/27c5c7e428c20be8. Report an issue: GitHub.