alibaba/open-code-review · error

TUI error: %w

Error message

TUI error: %w

What it means

This error wraps a failure from the Bubble Tea program run (`p.Run()`) inside `ocr config provider`. The interactive TUI could not start or crashed mid-session — commonly because the terminal cannot enter the required mode (not a TTY) or the terminal is too small.

Source

Thrown at cmd/opencodereview/provider_cmd.go:34

	"github.com/alibaba/open-code-review/internal/llm"
)

func runConfigProvider() error {
	configPath, err := defaultConfigPath()
	if err != nil {
		return err
	}

	cfg, err := loadOrCreateConfig(configPath)
	if err != nil {
		return fmt.Errorf("load config: %w", err)
	}

	m := newProviderTUI(cfg, configPath)
	p := tea.NewProgram(m)
	finalModel, err := p.Run()
	if err != nil {
		return fmt.Errorf("TUI error: %w", err)
	}

	final := finalModel.(providerTUIModel)

	if !final.confirmed {
		// TUI persists changes during the session; Esc only abandons the final
		// provider/API-key confirmation step.
		printWizardCancelled(final.savedInSession, "Configuration changes")
		return nil
	}

	result := final.result()

	if result.isManual {
		return applyManualConfig(configPath, cfg, result)
	}

	if result.isCustom {

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Run the command in an interactive terminal with a working stdin/stdout TTY.
  2. In CI, skip the TUI: edit the config file directly or use non-interactive setup.
  3. If using Docker, allocate a TTY: `docker run -it ...`.
  4. Read the wrapped cause after 'TUI error:' — it names the terminal-mode failure.

Example fix

# before (fails in CI)
ocr config provider | tee out.log
# after
# run interactively locally, or edit config non-interactively:
$EDITOR ~/.ocr/config.toml
Defensive patterns

Strategy: fallback

Validate before calling

// ensure a TTY before launching the TUI
if fi, _ := os.Stdin.Stat(); fi.Mode()&os.ModeCharDevice == 0 {
    return errors.New("interactive TUI requires a terminal; edit config file directly instead")
}

Try / catch

finalModel, err := p.Run()
if err != nil {
    return fmt.Errorf("TUI error: %w", err)
}

Prevention

When it happens

Trigger: Running `ocr config provider` in an environment without a usable TTY (CI jobs, piped/redirected stdout), or when tea.NewProgram(...).Run() fails due to terminal initialization errors.

Common situations: Attempting the interactive TUI inside Docker/CI where stdin is not a terminal; running over a stripped-down SSH connection; piping the command's output to a file.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/c83494940d6bab89. Report an issue: GitHub.