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

  1. Quote-free: change the config value to a bare number (cache_size: 1024)
  2. Cast the value to int when building Options programmatically: opts["cache_size"] = 1024 (not "1024")
  3. Parse strings before passing: n, _ := strconv.Atoi(s); opts[key] = n
  4. 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

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


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