cayleygraph/cayley · error
could not retrieve connmaxlifetime from options: %v
Error message
could not retrieve connmaxlifetime from options: %v
What it means
connect reads the "connmaxlifetime" string option via graph.Options.StringKey (default ""). If StringKey returns an error — e.g. the key is present but not a string — connect wraps it as "could not retrieve connmaxlifetime from options". Reached through Init or New.
Source
Thrown at graph/sql/quadstore.go:134
}
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)
if err != nil {
return nil, fmt.Errorf("couldn't parse connmaxlifetime string: %v", err)
}
}
// TODO(barakmich): Parse options for more friendly addr
conn, err := sql.Open(flavor, addr)
if err != nil {
clog.Errorf("Couldn't open database at %s: %#v", addr, err)
return nil, err
}
View on GitHub (pinned to 81dcd7d73e)
Solutions
- Set "connmaxlifetime" as a string duration (e.g. "1h30m") or omit the key.
- Quote the value in config files so loaders deliver a string.
- Check the wrapped underlying error for the exact type failure.
Example fix
// before
{"connmaxlifetime": 3600}
// after
{"connmaxlifetime": "1h"} Defensive patterns
Strategy: validation
Validate before calling
if v, ok := opts["connmaxlifetime"]; ok {
if _, isStr := v.(string); !isStr {
return fmt.Errorf("connmaxlifetime must be a string duration, got %T", v)
}
} Try / catch
qs, err := quadstore.New(addr, opts)
if err != nil {
if strings.Contains(err.Error(), "connmaxlifetime") && strings.Contains(err.Error(), "could not retrieve") {
// make the value a string duration
}
} Prevention
- Quote connmaxlifetime values ("1h") so loaders deliver strings.
- Never pass numbers or duration objects as the raw option value.
- Validate the options map types before New/Init.
When it happens
Trigger: New/Init call where opts has "connmaxlifetime" set to a non-string value (int, bool, map).
Common situations: Config where connmaxlifetime is an unquoted number (e.g. 3600 instead of "1h"); typed Options builders passing a duration object instead of a string.
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
- 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/7f579ea8c84962de.
Report an issue: GitHub.