{"record":{"id":"223ffb6540a79ca9","repo":"alibaba/open-code-review","slug":"load-config-w","errorCode":null,"errorMessage":"load config: %w","messagePattern":"load config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":118,"sourceCode":"// resolveConfigPath returns OCR_CONFIG_PATH when set, otherwise the default user config path.\n// Intentionally used only by read-only commands (e.g. ocr llm test). Write paths such as\n// config set and review keep defaultConfigPath() so a leaked OCR_CONFIG_PATH cannot redirect writes.\nfunc resolveConfigPath() (string, error) {\n\tif p := strings.TrimSpace(os.Getenv(\"OCR_CONFIG_PATH\")); p != \"\" {\n\t\treturn p, nil\n\t}\n\treturn defaultConfigPath()\n}\n\nfunc runConfigSet(key, value string) error {\n\tconfigPath, err := defaultConfigPath()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tcfg, err := loadOrCreateConfig(configPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load config: %w\", err)\n\t}\n\n\tif err := setConfigValue(cfg, key, value); err != nil {\n\t\treturn err\n\t}\n\n\tif err := saveConfig(configPath, cfg); err != nil {\n\t\treturn err\n\t}\n\n\tdisplayValue := value\n\tif shouldMaskConfigValue(key) {\n\t\tdisplayValue = maskKey(value)\n\t}\n\tfmt.Printf(\"Set %s = %s\\n\", key, displayValue)\n\tif warning := legacyLLMShadowWarning(cfg.Provider, key); warning != \"\" {\n\t\tfmt.Fprint(os.Stderr, warning)\n\t}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L100-L136","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (~/.opencodereview/config.json)\n{ \"provider\": \"anthropic\", }   // trailing comma\n// after\n{ \"provider\": \"anthropic\" }","handlingStrategy":"validation","validationCode":"// shell: validate config JSON before running ocr config set\nf=\"$HOME/.opencodereview/config.json\"\n[ -f \"$f\" ] && python3 -m json.tool \"$f\" > /dev/null || { echo \"config.json missing or invalid\"; exit 1; }","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"ocr\", \"config\", \"set\", key, val).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"load config:\") {\n\tos.Rename(cfgPath, cfgPath+\".corrupt\") // quarantine and retry with a fresh config\n}","preventionTips":["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."],"tags":["cli","config","json-parse"],"backgroundTag":"invalid-json-config","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}