alibaba/open-code-review · error

load config: %w

Error message

load config: %w

What it means

This error wraps a failure from loadOrCreateConfig when starting the interactive provider configuration command (`ocr config provider`). The config file could not be read or created — typically a permissions problem, an invalid path, or a malformed existing file that fails parsing.

Source

Thrown at cmd/opencodereview/provider_cmd.go:27

	"net/url"
	"os"
	"path/filepath"
	"strings"

	tea "charm.land/bubbletea/v2"

	"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
	}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Check the config path exists and is readable/writable: `ls -l <path>`; fix permissions with chmod/chown.
  2. If the file is corrupt, fix the syntax or delete it and let the TUI recreate a fresh config.
  3. Pass an explicit writable --config path if the default location is not writable.
  4. Read the wrapped cause after 'load config:' for the precise filesystem or parse error.

Example fix

// before
$ ocr config provider
load config: open /root/.ocr/config.toml: permission denied
// after
$ chmod u+rw /root/.ocr/config.toml && ocr config provider
Defensive patterns

Strategy: validation

Validate before calling

dir := filepath.Dir(configPath)
if err := os.MkdirAll(dir, 0o755); err != nil { return err }
if fi, err := os.Stat(configPath); err == nil && fi.Mode().Perm()&0o600 == 0 {
    os.Chmod(configPath, 0o600)
}

Try / catch

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

Prevention

When it happens

Trigger: Running `ocr config provider` when loadOrCreateConfig(configPath) errors: unwritable directory for a new config, unreadable existing config, or a corrupt/malformed config file.

Common situations: Running under a user without write access to $HOME; read-only CI containers; hand-edited config with broken syntax; wrong --config path pointing into a non-existent directory.

Related errors


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