cayleygraph/cayley · error

could not parse config file %q: %v

Error message

could not parse config file %q: %v

What it means

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.

Source

Thrown at graph/gaedatastore/config.go:139

}

// LoadConf reads a JSON-encoded config contained in the given file. A zero value
// config is returned if the filename is empty.
func LoadConf(file string) (*Config, error) {
	config := &Config{}
	if file == "" {
		return config, nil
	}
	f, err := os.Open(file)
	if err != nil {
		return nil, fmt.Errorf("could not open config file %q: %v", file, err)
	}
	defer f.Close()

	dec := json.NewDecoder(f)
	err = dec.Decode(config)
	if err != nil {
		return nil, fmt.Errorf("could not parse config file %q: %v", file, err)
	}
	return config, nil
}

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. 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.
  2. Remove any BOM and ensure UTF-8 encoding without comments (this is strict JSON, not JSONC/YAML).
  3. Compare the structure against the gaedatastore.Config struct fields and fix mismatched types.
  4. Start from a known-good example config for gaedatastore and re-apply your settings.

Example fix

// before: gaedatastore.json
{ "timeout": "30", } // trailing comma + string where number expected
// after
{ "timeout": 30 }
Defensive patterns

Strategy: validation

Validate before calling

// validate before loading
var probe map[string]interface{}
b, _ := ioutil.ReadFile(path)
if err := json.Unmarshal(b, &probe); err != nil {
    return fmt.Errorf("config %s is not valid JSON: %v", path, err)
}

Try / catch

if err := dec.Decode(config); err != nil {
    var je *json.SyntaxError
    if errors.As(err, &je) {
        log.Fatalf("JSON syntax error at offset %d: %v", je.Offset, je)
    }
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/da8bb724bb6fda0c. Report an issue: GitHub.