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

  1. Set "maxopenconnections" to a valid integer in the options (or remove the key to use the default).
  2. Inspect the wrapped %v error for the exact IntKey parse failure.
  3. 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

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


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