{"record":{"id":"141a224cb185acfd","repo":"cayleygraph/cayley","slug":"errdatabaseexists","errorCode":"ErrDatabaseExists","errorMessage":"quadstore: cannot init; database already exists","messagePattern":"quadstore: cannot init; database already exists","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"graph/quadstore.go","lineNumber":156,"sourceCode":"\t}\n\n\treturn def, nil\n}\n\nfunc (d Options) BoolKey(key string, def bool) (bool, error) {\n\tif val, ok := d[key]; ok {\n\t\tif v, ok := val.(bool); ok {\n\t\t\treturn v, nil\n\t\t}\n\n\t\treturn def, fmt.Errorf(\"Invalid %s parameter type from config: %T\", key, val)\n\t}\n\n\treturn def, nil\n}\n\nvar (\n\tErrDatabaseExists = errors.New(\"quadstore: cannot init; database already exists\")\n\tErrNotInitialized = errors.New(\"quadstore: not initialized\")\n)\n","sourceCodeStart":138,"sourceCodeEnd":159,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/quadstore.go#L138-L159","documentation":"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.","triggerScenarios":"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.","commonSituations":"Re-running cayley init against an existing data directory; automated scripts that init idempotently; deploying where the persistent volume already contains a previous database.","solutions":["Skip Init when the database exists: treat graph.ErrDatabaseExists as 'already initialized' and continue (like cayley's own database.go does).","Use the existing database with graph.New/open instead of initializing again.","If a fresh database is truly required, delete or move the existing data directory first."],"exampleFix":"// before\nif err := initDatabase(); err != nil { return err }\n// after\nif err := initDatabase(); err == graph.ErrDatabaseExists {\n    log.Info(\"database already initialized, skipping init\")\n} else if err != nil {\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(path); err == nil {\n    // path exists; likely already initialized\n}","typeGuard":null,"tryCatchPattern":"if err := initDatabase(); err == graph.ErrDatabaseExists {\n    log.Info(\"database already initialized, skipping init\")\n} else if err != nil {\n    return err\n}","preventionTips":["Make init idempotent by explicitly handling ErrDatabaseExists.","Probe with metadata/new before running init in scripts.","Use separate flags for 'create if missing' vs 'fail if exists' semantics."],"tags":["go","quadstore","initialization","idempotency"],"backgroundTag":"file-already-exists","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}