cayleygraph/cayley · error
Invalid %s parameter type from config: %T
Error message
Invalid %s parameter type from config: %T
What it means
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.
Source
Thrown at graph/quadstore.go:126
// Close the quad store and clean up. (Flush to disk, cleanly
// sever connections, etc)
Close() error
}
type Options map[string]interface{}
var (
typeInt = reflect.TypeOf(int(0))
)
func (d Options) IntKey(key string, def int) (int, error) {
if val, ok := d[key]; ok {
if reflect.TypeOf(val).ConvertibleTo(typeInt) {
i := reflect.ValueOf(val).Convert(typeInt).Int()
return int(i), nil
}
return def, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
}
return def, nil
}
func (d Options) StringKey(key string, def string) (string, error) {
if val, ok := d[key]; ok {
if v, ok := val.(string); ok {
return v, nil
}
return def, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
}
return def, nil
}
func (d Options) BoolKey(key string, def bool) (bool, error) {
if val, ok := d[key]; ok {View on GitHub (pinned to 81dcd7d73e)
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
Example fix
// before
opts := graph.Options{"cache_size": "1024"}
// after
opts := graph.Options{"cache_size": 1024} // or strconv.Atoi of the string first Defensive patterns
Strategy: validation
Validate before calling
func validInt(v interface{}) bool {
t := reflect.TypeOf(v)
return t != nil && reflect.TypeOf(int64(0)).ConvertibleTo(t) && t != reflect.TypeOf("")
}
// usage: if !validInt(opts["cache_size"]) { fix before calling } Type guard
func isIntLike(v interface{}) bool {
switch v.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: return true }
return false
} Try / catch
n, err := opts.IntKey("cache_size", 1024)
if err != nil {
log.Warnf("bad cache_size: %v, using default", err)
n = 1024
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- could not retrieve maxopenconnections from options: %v
- could not retrieve maxIdleConnections from options: %v
- could not retrieve connmaxlifetime from options: %v
- couldn't parse connmaxlifetime string: %v
- token not valid
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/583e3b3abbb5d989.
Report an issue: GitHub.