{"record":{"id":"697c2623993ded85","repo":"alibaba/open-code-review","slug":"parse-config-w-697c26","errorCode":null,"errorMessage":"parse config: %w","messagePattern":"parse config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/llm/resolver.go","lineNumber":354,"sourceCode":"\tModel           string                         `json:\"model,omitempty\"`\n\tProviders       map[string]providerEntryConfig `json:\"providers,omitempty\"`\n\tCustomProviders map[string]providerEntryConfig `json:\"custom_providers,omitempty\"`\n\tLlm             llmFileConfig                  `json:\"llm,omitempty\"`\n}\n\n// tryOCRConfig reads the OCR config file.\nfunc tryOCRConfig(path string, opts ResolveOptions) (ResolvedEndpoint, bool, error) {\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn ResolvedEndpoint{}, false, nil\n\t\t}\n\t\treturn ResolvedEndpoint{}, false, err\n\t}\n\n\tvar cfg configFile\n\tif err := json.Unmarshal(data, &cfg); err != nil {\n\t\treturn ResolvedEndpoint{}, false, fmt.Errorf(\"parse config: %w\", err)\n\t}\n\n\tif opts.Provider != \"\" {\n\t\tif opts.Provider != cfg.Provider {\n\t\t\tcfg.Model = \"\"\n\t\t}\n\t\tcfg.Provider = opts.Provider\n\t}\n\tif cfg.Provider != \"\" {\n\t\treturn tryProviderConfig(cfg, opts.Model)\n\t}\n\n\treturn tryLegacyLlmConfig(cfg, opts.Model)\n}\n\n// tryProviderConfig resolves an endpoint from the provider-based configuration.\nfunc tryProviderConfig(cfg configFile, modelOverride string) (ResolvedEndpoint, bool, error) {\n\tpreset, isPreset := LookupProvider(cfg.Provider)","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/llm/resolver.go#L336-L372","documentation":"Raised by tryOCRConfig when the OCR config file exists but json.Unmarshal fails, wrapped as \"parse config: <cause>\". The file is not valid JSON (or its structure mismatches the configFile schema), so the resolver cannot proceed and reports the underlying decoder error.","triggerScenarios":"os.ReadFile succeeded on the config path but the content is malformed JSON: trailing commas, comments, single quotes, BOM, truncated file, or a JSON value whose type does not match the schema (e.g. \"providers\": [] instead of an object).","commonSituations":"Hand-editing config.json and leaving a trailing comma; pasting JSONC-style comments; an editor or tool overwriting the file mid-write; mixing up the providers object for an array.","solutions":["Validate the file with a JSON parser (e.g. jq . config.json or python -m json.tool config.json) and fix the reported syntax error","Remove comments and trailing commas — only strict JSON is accepted","Restore the file from backup or re-run the tool's init/setup command to regenerate it","Check that \"providers\" and \"custom_providers\" are JSON objects (string keys), not arrays"],"exampleFix":"// before (config.json)\n{\n  \"provider\": \"bedrock\",  // my provider\n  \"providers\": { \"bedrock\": { \"aws_region\": \"us-east-1\", } }\n}\n\n// after\n{\n  \"provider\": \"bedrock\",\n  \"providers\": { \"bedrock\": { \"aws_region\": \"us-east-1\" } }\n}","handlingStrategy":"try-catch","validationCode":"data, err := os.ReadFile(cfgPath)\nif err == nil {\n    var v any\n    if jerr := json.Unmarshal(data, &v); jerr != nil {\n        return fmt.Errorf(\"config %s is not valid JSON: %w\", cfgPath, jerr)\n    }\n}","typeGuard":null,"tryCatchPattern":"var syntaxErr *json.SyntaxError\nif errors.As(err, &syntaxErr) {\n    log.Fatalf(\"config.json syntax error at offset %d: %v\", syntaxErr.Offset, syntaxErr)\n}","preventionTips":["Run `jq . config.json` after every manual edit","Never leave trailing commas or comments — the parser is strict JSON","Generate the file with the tool's init command instead of hand-writing it","Keep config.json in a linter/pre-commit JSON check"],"tags":["configuration","json","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}