alibaba/open-code-review · error

load app config: %w

Error message

load app config: %w

What it means

loadLLMRuntime reads the application config from defaultConfigPath() via LoadAppConfig and wraps failures as `load app config: %w`. A missing config file is tolerated (appCfg may be nil and defaults apply), so this error means the file exists but is invalid or unreadable — bad syntax, unknown fields, wrong types.

Source

Thrown at cmd/opencodereview/shared.go:227

// from the user's default config path (applying the configured language to
// tpl — defaulting when the config file is absent), resolves the LLM
// endpoint (honoring resolveOpts), and
// returns the runtime bundle. tpl is mutated in place.
func loadLLMRuntime(tpl *template.Template, toolConfigPath string, resolveOpts llm.ResolveOptions) (*llmRuntime, error) {
	toolEntries, err := toolsconfig.Load(toolConfigPath)
	if err != nil {
		return nil, fmt.Errorf("load tools: %w", err)
	}
	planToolDefs := agent.BuildToolDefs(toolEntries, true)
	mainToolDefs := agent.BuildToolDefs(toolEntries, false)

	cfgPath, err := defaultConfigPath()
	if err != nil {
		return nil, err
	}
	appCfg, err := LoadAppConfig(cfgPath)
	if err != nil {
		return nil, fmt.Errorf("load app config: %w", err)
	}
	// Apply the language directive even when the config file is missing
	// (upstream #fix: ApplyLanguage with empty lang falls back to default).
	var lang string
	if appCfg != nil {
		lang = appCfg.Language
	}
	tpl.ApplyLanguage(lang)

	ep, err := llm.ResolveEndpointWithOptions(cfgPath, resolveOpts)
	if err != nil {
		return nil, fmt.Errorf("resolve LLM endpoint: %w", err)
	}

	retryCollector := newRetryCollector()

	return &llmRuntime{
		Client:         llm.NewLLMClient(ep, retryCollector),

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Fix the syntax/type error at the reported line in the config file
  2. Temporarily move the config aside to confirm it is the cause, then re-add settings incrementally
  3. Fix permissions on the config file and its parent directory
  4. Regenerate a fresh default config and re-apply your settings

Example fix

// before (~/.config/ocr/config.json)
{ "language": "en", }   // trailing comma
// after
{ "language": "en" }
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(cfgPath)
if err != nil {
	return err
}
var raw map[string]any
if err := json.Unmarshal(data, &raw); err != nil {
	return fmt.Errorf("config %s is not valid JSON: %w", cfgPath, err)
}

Try / catch

if err != nil {
	// config exists but is broken; move it aside and start from defaults
	os.Rename(cfgPath, cfgPath+".bak")
	return retryWithDefaults()
}

Prevention

When it happens

Trigger: ocr review/scan startup when the user's config file (at the default config path) exists but fails to parse or validate; file unreadable due to permissions; hand-edited JSON/YAML with a syntax error.

Common situations: Manual edits leaving a trailing comma or wrong indentation; a `language` value of the wrong type; config written by another tool version with an incompatible field; file locked or owned by another user.

Related errors


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