cayleygraph/cayley · warning

ErrDatabaseExists

ErrDatabaseExists

Error message

quadstore: cannot init; database already exists

What it means

ErrDatabaseExists is the quadstore-level sentinel signaling that Init was attempted on a location that already holds an initialized database. Init and Create return it so callers can distinguish 'already initialized' (usually harmless) from genuine failures, as seen in cmd/cayley where it logs and skips init.

Source

Thrown at graph/quadstore.go:156

	}

	return def, nil
}

func (d Options) BoolKey(key string, def bool) (bool, error) {
	if val, ok := d[key]; ok {
		if v, ok := val.(bool); ok {
			return v, nil
		}

		return def, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
	}

	return def, nil
}

var (
	ErrDatabaseExists = errors.New("quadstore: cannot init; database already exists")
	ErrNotInitialized = errors.New("quadstore: not initialized")
)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Skip Init when the database exists: treat graph.ErrDatabaseExists as 'already initialized' and continue (like cayley's own database.go does).
  2. Use the existing database with graph.New/open instead of initializing again.
  3. If a fresh database is truly required, delete or move the existing data directory first.

Example fix

// before
if err := initDatabase(); err != nil { return err }
// after
if err := initDatabase(); err == graph.ErrDatabaseExists {
    log.Info("database already initialized, skipping init")
} else if err != nil {
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(path); err == nil {
    // path exists; likely already initialized
}

Try / catch

if err := initDatabase(); err == graph.ErrDatabaseExists {
    log.Info("database already initialized, skipping init")
} else if err != nil {
    return err
}

Prevention

When it happens

Trigger: Calling graph.Init / database init (cayley init) on a path that already contains initialized quadstore data; leveldb Create maps os.IsExist errors to this sentinel.

Common situations: Re-running cayley init against an existing data directory; automated scripts that init idempotently; deploying where the persistent volume already contains a previous database.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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