{"record":{"id":"da8bb724bb6fda0c","repo":"cayleygraph/cayley","slug":"could-not-parse-config-file-q-v","errorCode":null,"errorMessage":"could not parse config file %q: %v","messagePattern":"could not parse config file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/gaedatastore/config.go","lineNumber":139,"sourceCode":"}\n\n// LoadConf reads a JSON-encoded config contained in the given file. A zero value\n// config is returned if the filename is empty.\nfunc LoadConf(file string) (*Config, error) {\n\tconfig := &Config{}\n\tif file == \"\" {\n\t\treturn config, nil\n\t}\n\tf, err := os.Open(file)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not open config file %q: %v\", file, err)\n\t}\n\tdefer f.Close()\n\n\tdec := json.NewDecoder(f)\n\terr = dec.Decode(config)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not parse config file %q: %v\", file, err)\n\t}\n\treturn config, nil\n}\n","sourceCodeStart":121,"sourceCodeEnd":143,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/gaedatastore/config.go#L121-L143","documentation":"LoadConf successfully opens the config file but json.Decoder.Decode fails to parse its contents into the gaedatastore Config struct, so the JSON decode error is wrapped with the file path. This indicates malformed or structurally incompatible JSON configuration.","triggerScenarios":"Calling LoadConf with a file whose contents are not valid JSON, or whose shape does not match the Config struct (e.g. wrong types for fields).","commonSituations":"Hand-edited config with a missing brace, trailing comma, or comments (JSON has none); saving the file with a BOM; using YAML by mistake instead of JSON; field type mismatch like a string where a number is expected.","solutions":["Validate the file with a JSON parser/linter (e.g. `python -m json.tool <file>`) and fix syntax errors such as trailing commas or unquoted keys.","Remove any BOM and ensure UTF-8 encoding without comments (this is strict JSON, not JSONC/YAML).","Compare the structure against the gaedatastore.Config struct fields and fix mismatched types.","Start from a known-good example config for gaedatastore and re-apply your settings."],"exampleFix":"// before: gaedatastore.json\n{ \"timeout\": \"30\", } // trailing comma + string where number expected\n// after\n{ \"timeout\": 30 }","handlingStrategy":"validation","validationCode":"// validate before loading\nvar probe map[string]interface{}\nb, _ := ioutil.ReadFile(path)\nif err := json.Unmarshal(b, &probe); err != nil {\n    return fmt.Errorf(\"config %s is not valid JSON: %v\", path, err)\n}","typeGuard":null,"tryCatchPattern":"if err := dec.Decode(config); err != nil {\n    var je *json.SyntaxError\n    if errors.As(err, &je) {\n        log.Fatalf(\"JSON syntax error at offset %d: %v\", je.Offset, je)\n    }\n    return err\n}","preventionTips":["Lint config files with a strict JSON validator in CI.","Do not hand-edit JSON; use tools that guarantee valid syntax.","Save as UTF-8 without BOM and without comments."],"tags":["config","json","gae"],"backgroundTag":"json-parse-error","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}