alibaba/open-code-review · error

model name cannot be empty

Error message

model name cannot be empty

What it means

runConfigModel validates the model chosen in the TUI after the program exits; if final.selectedModel() is empty, it refuses to persist and returns this error. It guards against writing an empty Model value into the config, which would leave the CLI without a usable model for LLM calls.

Source

Thrown at cmd/opencodereview/provider_cmd.go:385

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

	final := finalModel.(modelTUIModel)
	if final.cancelled {
		printWizardCancelled(final.savedInSession, "Model list changes")
		return nil
	}

	selectedModel := final.selectedModel()
	if selectedModel == "" {
		return fmt.Errorf("model name cannot be empty")
	}

	if isCustom {
		if cfg.CustomProviders == nil {
			cfg.CustomProviders = make(map[string]ProviderEntry)
		}
		entry := cfg.CustomProviders[cfg.Provider]
		entry.Model = selectedModel
		entry.Models = ensureModelInList(entry.Models, selectedModel)
		cfg.CustomProviders[cfg.Provider] = entry
	} else {
		if cfg.Providers == nil {
			cfg.Providers = make(map[string]ProviderEntry)
		}
		entry := cfg.Providers[cfg.Provider]
		entry.Model = selectedModel
		// Use registry-only list: provider.Models was captured before the TUI and
		// may include stale entry.Models from add/delete during the session.

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Add or select a model for the provider before saving (use the provider TUI to add one)
  2. Verify the provider entry has a non-empty Models list in the config file
  3. Check network/registry availability so official provider model lists load correctly
  4. If it persists, cancel out of the wizard instead of confirming with no selection

Example fix

// before: confirming an empty list in the TUI
selectedModel := final.selectedModel() // ""
// after: add a model first (custom provider)
$ ocr config provider add-model my-model
then re-run the model picker and confirm a highlighted selection
Defensive patterns

Strategy: validation

Validate before calling

// before trusting the selection
if selected := final.selectedModel(); strings.TrimSpace(selected) == "" {
    return fmt.Errorf("model name cannot be empty")
}

Try / catch

if err := runConfigModel(...); err != nil {
    if strings.Contains(err.Error(), "model name cannot be empty") {
        fmt.Fprintln(os.Stderr, "no model selected — pick a model or cancel with Esc/q")
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Finishing the model-selection TUI without a selection (e.g. the model list is empty or the current selection index points at nothing) and not cancelling — finalModel is non-cancelled but selectedModel() returns "".

Common situations: A custom provider with an empty Models list; a registry/official provider whose model list failed to load; a TUI state bug where selection was never initialized.

Related errors


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