{"record":{"id":"e9a31be267c2afac","repo":"cayleygraph/cayley","slug":"errnobucket","errorCode":"ErrNoBucket","errorMessage":"kv: no bucket","messagePattern":"kv: no bucket","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/kv/quadstore.go","lineNumber":39,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"sync\"\n\n\t\"github.com/cayleygraph/quad\"\n\t\"github.com/cayleygraph/quad/pquads\"\n\t\"github.com/hidal-go/hidalgo/kv\"\n\tboom \"github.com/tylertreat/BoomFilters\"\n\n\t\"github.com/cayleygraph/cayley/graph\"\n\t\"github.com/cayleygraph/cayley/graph/proto\"\n\t\"github.com/cayleygraph/cayley/graph/refs\"\n\t\"github.com/cayleygraph/cayley/internal/lru\"\n\t\"github.com/cayleygraph/cayley/query/shape\"\n)\n\nvar (\n\tErrNoBucket  = errors.New(\"kv: no bucket\")\n\tErrEmptyPath = errors.New(\"kv: path to the database must be specified\")\n)\n\ntype Registration struct {\n\tNewFunc      NewFunc\n\tInitFunc     InitFunc\n\tIsPersistent bool\n}\n\ntype InitFunc func(string, graph.Options) (kv.KV, error)\ntype NewFunc func(string, graph.Options) (kv.KV, error)\n\nfunc Register(name string, r Registration) {\n\tgraph.RegisterQuadStore(name, graph.QuadStoreRegistration{\n\t\tInitFunc: func(addr string, opt graph.Options) error {\n\t\t\tif !r.IsPersistent {\n\t\t\t\treturn nil\n\t\t\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/kv/quadstore.go#L21-L57","documentation":"ErrNoBucket is the sentinel error returned by the kv quadstore layer when the expected metadata bucket does not exist. Callers use it to distinguish 'database not initialized' (no metadata bucket) from real failures: New maps it to graph.ErrNotInitialized, and Init checks that the metadata bucket is absent before creating a fresh database.","triggerScenarios":"Calling kv.New(...) on a kv handle whose metadata bucket was never created (i.e. Init was never run, or a wrong/empty path was opened). Also used internally by Init/New/getSize when probing bucket existence.","commonSituations":"Opening a database path before running cayley init; pointing at the wrong directory so no bucket exists; a fresh empty file created by the kv backend; deleting the metadata bucket manually.","solutions":["Run the Init/create step first (cayley init, or graph.Init) so the metadata bucket is created, then New.","Verify the path points at an existing, initialized database directory.","In code, treat ErrNoBucket as graph.ErrNotInitialized and branch to initialization logic."],"exampleFix":"// before\nqs, err := kv.New(db) // ErrNoBucket on empty database\n// after\nif err := graph.Init(ctx, opts); err != nil && err != graph.ErrDatabaseExists {\n    return err\n}\nqs, err := kv.New(db)","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(path); os.IsNotExist(err) {\n    // database not created yet: run init first\n}","typeGuard":null,"tryCatchPattern":"qs, err := kv.New(db)\nif errors.Is(err, kv.ErrNoBucket) || errors.Is(err, graph.ErrNotInitialized) {\n    if err := graph.Init(ctx, opts); err != nil {\n        return err\n    }\n    qs, err = kv.New(db)\n}","preventionTips":["Always run cayley init (or graph.Init) before opening a new database path.","Validate the configured path in startup checks.","Compare against errors.Is(err, kv.ErrNoBucket) rather than string matching."],"tags":["go","kv-store","initialization","database"],"backgroundTag":"database-not-initialized","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"}