{"record":{"id":"583e3b3abbb5d989","repo":"cayleygraph/cayley","slug":"invalid-s-parameter-type-from-config-t","errorCode":null,"errorMessage":"Invalid %s parameter type from config: %T","messagePattern":"Invalid (.+?) parameter type from config: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/quadstore.go","lineNumber":126,"sourceCode":"\t// Close the quad store and clean up. (Flush to disk, cleanly\n\t// sever connections, etc)\n\tClose() error\n}\n\ntype Options map[string]interface{}\n\nvar (\n\ttypeInt = reflect.TypeOf(int(0))\n)\n\nfunc (d Options) IntKey(key string, def int) (int, error) {\n\tif val, ok := d[key]; ok {\n\t\tif reflect.TypeOf(val).ConvertibleTo(typeInt) {\n\t\t\ti := reflect.ValueOf(val).Convert(typeInt).Int()\n\t\t\treturn int(i), nil\n\t\t}\n\n\t\treturn def, fmt.Errorf(\"Invalid %s parameter type from config: %T\", key, val)\n\t}\n\treturn def, nil\n}\n\nfunc (d Options) StringKey(key string, def string) (string, error) {\n\tif val, ok := d[key]; ok {\n\t\tif v, ok := val.(string); ok {\n\t\t\treturn v, nil\n\t\t}\n\n\t\treturn def, fmt.Errorf(\"Invalid %s parameter type from config: %T\", key, val)\n\t}\n\n\treturn def, nil\n}\n\nfunc (d Options) BoolKey(key string, def bool) (bool, error) {\n\tif val, ok := d[key]; ok {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/quadstore.go#L108-L144","documentation":"Options.IntKey reads an integer-valued config key. If the key exists but its Go type is not convertible to int64 (e.g. a string \"100\", a bool, a slice), the default value is returned together with this error instead of silently coercing.","triggerScenarios":"Passing options to connect/quadIndexes where a numeric option (e.g. cache size, index size) is given as a string or other non-numeric type in the options map/viper config.","commonSituations":"YAML/JSON config where a numeric field was quoted (cache_size: \"1024\"), environment variables parsed as strings, or programmatic Options maps built with wrong types.","solutions":["Quote-free: change the config value to a bare number (cache_size: 1024)","Cast the value to int when building Options programmatically: opts[\"cache_size\"] = 1024 (not \"1024\")","Parse strings before passing: n, _ := strconv.Atoi(s); opts[key] = n","Handle the returned error from IntKey and fall back to the default"],"exampleFix":"// before\nopts := graph.Options{\"cache_size\": \"1024\"}\n// after\nopts := graph.Options{\"cache_size\": 1024} // or strconv.Atoi of the string first","handlingStrategy":"validation","validationCode":"func validInt(v interface{}) bool {\n    t := reflect.TypeOf(v)\n    return t != nil && reflect.TypeOf(int64(0)).ConvertibleTo(t) && t != reflect.TypeOf(\"\")\n}\n// usage: if !validInt(opts[\"cache_size\"]) { fix before calling }","typeGuard":"func isIntLike(v interface{}) bool {\n    switch v.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: return true }\n    return false\n}","tryCatchPattern":"n, err := opts.IntKey(\"cache_size\", 1024)\nif err != nil {\n    log.Warnf(\"bad cache_size: %v, using default\", err)\n    n = 1024\n}","preventionTips":["Never quote numeric values in YAML/JSON configs","Convert env vars with strconv before putting them in Options","Unit-test option parsing with real config files","Always check the error return of IntKey"],"tags":["config","type-mismatch","options"],"backgroundTag":"invalid-config-value","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"}