alibaba/open-code-review · error
load config: %w
Error message
load config: %w
What it means
runConfigSet wraps failures from loadOrCreateConfig with "load config: %w". loadOrCreateConfig only fails when the config file exists but cannot be read (permissions) or parsed as JSON ("parse config: ..."). A missing file is not an error — it creates a fresh config — so this always points at a corrupt or inaccessible existing ~/.opencodereview/config.json.
Source
Thrown at cmd/opencodereview/config_cmd.go:118
// resolveConfigPath returns OCR_CONFIG_PATH when set, otherwise the default user config path.
// Intentionally used only by read-only commands (e.g. ocr llm test). Write paths such as
// config set and review keep defaultConfigPath() so a leaked OCR_CONFIG_PATH cannot redirect writes.
func resolveConfigPath() (string, error) {
if p := strings.TrimSpace(os.Getenv("OCR_CONFIG_PATH")); p != "" {
return p, nil
}
return defaultConfigPath()
}
func runConfigSet(key, value string) error {
configPath, err := defaultConfigPath()
if err != nil {
return err
}
cfg, err := loadOrCreateConfig(configPath)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
if err := setConfigValue(cfg, key, value); err != nil {
return err
}
if err := saveConfig(configPath, cfg); err != nil {
return err
}
displayValue := value
if shouldMaskConfigValue(key) {
displayValue = maskKey(value)
}
fmt.Printf("Set %s = %s\n", key, displayValue)
if warning := legacyLLMShadowWarning(cfg.Provider, key); warning != "" {
fmt.Fprint(os.Stderr, warning)
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Validate the JSON: `python3 -m json.tool ~/.opencodereview/config.json` — fix any syntax errors it reports.
- Check permissions: `ls -l ~/.opencodereview/config.json`; ensure the current user can read it.
- If corrupt, back it up and remove or recreate it: `mv ~/.opencodereview/config.json ~/.opencodereview/config.json.bak`, then rerun the set command.
- Inspect the wrapped cause in the error message ("parse config: ..." vs permission denied) to pick the right fix.
Example fix
// before (~/.opencodereview/config.json)
{ "provider": "anthropic", } // trailing comma
// after
{ "provider": "anthropic" } Defensive patterns
Strategy: validation
Validate before calling
// shell: validate config JSON before running ocr config set
f="$HOME/.opencodereview/config.json"
[ -f "$f" ] && python3 -m json.tool "$f" > /dev/null || { echo "config.json missing or invalid"; exit 1; } Try / catch
out, err := exec.Command("ocr", "config", "set", key, val).CombinedOutput()
if err != nil && strings.Contains(string(out), "load config:") {
os.Rename(cfgPath, cfgPath+".corrupt") // quarantine and retry with a fresh config
} Prevention
- Always validate config.json with a JSON linter after hand edits.
- Never put comments or trailing commas in config.json (strict JSON only).
- Let ocr's own `config set` commands modify the file instead of editing by hand.
- Watch the wrapped cause: 'parse config' means syntax, 'permission denied' means file access.
When it happens
Trigger: Running `ocr config set <key> <value>` when ~/.opencodereview/config.json exists but is unreadable (wrong owner/permissions) or contains invalid JSON (truncated write, hand-edit mistake, JSON5/comments, trailing commas).
Common situations: Hand-editing config.json and leaving a syntax error; a previous ocr process crashed mid-write; the file was created by another tool or version with a different schema; permissions changed by a chmod/chown script; NFS/home-sync conflicts producing partial files.
Related errors
- unset supports provider, max_tokens, effort, custom_provider
- MCP server %q not found
- custom provider %q not found
- read app config %s: %w
- invalid max_tokens %q: must be a positive integer
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/223ffb6540a79ca9.
Report an issue: GitHub.