alibaba/open-code-review · error
parse config: %w
Error message
parse config: %w
What it means
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.
Source
Thrown at internal/llm/resolver.go:354
Model string `json:"model,omitempty"`
Providers map[string]providerEntryConfig `json:"providers,omitempty"`
CustomProviders map[string]providerEntryConfig `json:"custom_providers,omitempty"`
Llm llmFileConfig `json:"llm,omitempty"`
}
// tryOCRConfig reads the OCR config file.
func tryOCRConfig(path string, opts ResolveOptions) (ResolvedEndpoint, bool, error) {
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return ResolvedEndpoint{}, false, nil
}
return ResolvedEndpoint{}, false, err
}
var cfg configFile
if err := json.Unmarshal(data, &cfg); err != nil {
return ResolvedEndpoint{}, false, fmt.Errorf("parse config: %w", err)
}
if opts.Provider != "" {
if opts.Provider != cfg.Provider {
cfg.Model = ""
}
cfg.Provider = opts.Provider
}
if cfg.Provider != "" {
return tryProviderConfig(cfg, opts.Model)
}
return tryLegacyLlmConfig(cfg, opts.Model)
}
// tryProviderConfig resolves an endpoint from the provider-based configuration.
func tryProviderConfig(cfg configFile, modelOverride string) (ResolvedEndpoint, bool, error) {
preset, isPreset := LookupProvider(cfg.Provider)View on GitHub (pinned to 5cf97d0d15)
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
Example fix
// before (config.json)
{
"provider": "bedrock", // my provider
"providers": { "bedrock": { "aws_region": "us-east-1", } }
}
// after
{
"provider": "bedrock",
"providers": { "bedrock": { "aws_region": "us-east-1" } }
} Defensive patterns
Strategy: try-catch
Validate before calling
data, err := os.ReadFile(cfgPath)
if err == nil {
var v any
if jerr := json.Unmarshal(data, &v); jerr != nil {
return fmt.Errorf("config %s is not valid JSON: %w", cfgPath, jerr)
}
} Try / catch
var syntaxErr *json.SyntaxError
if errors.As(err, &syntaxErr) {
log.Fatalf("config.json syntax error at offset %d: %v", syntaxErr.Offset, syntaxErr)
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- load rules: %w
- parse config: %w
- parse app config: %w
- invalid JSON for llm.extra_body: %w
- invalid JSON array for %s: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/697c2623993ded85.
Report an issue: GitHub.