cayleygraph/cayley · error
could not retrieve maxopenconnections from options: %v
Error message
could not retrieve maxopenconnections from options: %v
What it means
connect reads the "maxopenconnections" integer option with a default of -1 via graph.Options.IntKey. If IntKey returns an error (typically the key exists but is not an integer, per the options API), connect wraps it in "could not retrieve maxopenconnections from options" and aborts. Init and New both route through connect.
Source
Thrown at graph/sql/quadstore.go:122
type QuadStore struct {
db *sql.DB
opt *Optimizer
flavor Registration
ids *lru.Cache
sizes *lru.Cache
noSizes bool
mu sync.RWMutex
nodes int64
quads int64
}
func connect(addr string, flavor string, opts graph.Options) (*sql.DB, error) {
maxOpenConnections, err := opts.IntKey("maxopenconnections", -1)
if err != nil {
return nil, fmt.Errorf("could not retrieve maxopenconnections from options: %v", err)
}
maxIdleConnections, err := opts.IntKey("maxidleconnections", -1)
if err != nil {
return nil, fmt.Errorf("could not retrieve maxIdleConnections from options: %v", err)
}
connMaxLifetime, err := opts.StringKey("connmaxlifetime", "")
if err != nil {
return nil, fmt.Errorf("could not retrieve connmaxlifetime from options: %v", err)
}
var connDuration time.Duration
if connMaxLifetime != "" {
connDuration, err = time.ParseDuration(connMaxLifetime)
View on GitHub (pinned to 81dcd7d73e)
Solutions
- Set "maxopenconnections" to a valid integer in the options (or remove the key to use the default).
- Inspect the wrapped %v error for the exact IntKey parse failure.
- Check the config source for quotes/whitespace making the value a string.
Example fix
// before
opts{"maxopenconnections": "twenty"}
// after
opts{"maxopenconnections": 20} Defensive patterns
Strategy: validation
Validate before calling
// before New/Init:
if v, ok := opts["maxopenconnections"]; ok {
if _, err := strconv.Atoi(fmt.Sprint(v)); err != nil {
return fmt.Errorf("maxopenconnections must be an integer, got %v", v)
}
} Try / catch
qs, err := quadstore.New(addr, opts)
if err != nil {
if strings.Contains(err.Error(), "maxopenconnections") {
// fix the option type/value and retry
}
} Prevention
- Keep numeric options as JSON/YAML numbers, not strings.
- Use typed option builders instead of raw maps.
- Validate the full options map before calling New/Init.
When it happens
Trigger: Calling graph/sql quadstore New(addr, opts) or Init with opts where the "maxopenconnections" key is present with a non-integer value (e.g. "ten", "100abc").
Common situations: Config file/env where maxopenconnections is quoted or mistyped; YAML/JSON config feeding strings into IntKey; copy-pasting a boolean or float value into the option.
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 maxIdleConnections from options: %v
- could not retrieve connmaxlifetime from options: %v
- couldn't parse connmaxlifetime string: %v
- Invalid %s parameter type from config: %T
- could not open config file %q: %v
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/bbcbb66d6d4ec269.
Report an issue: GitHub.