{"record":{"id":"52c57e2d9a510c89","repo":"cayleygraph/cayley","slug":"passed-value-was-not-a-quad-primitive-t","errorCode":null,"errorMessage":"passed value was not a quad primitive: %T","messagePattern":"passed value was not a quad primitive: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/kv/quadstore.go","lineNumber":378,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn values, nil\n}\n\nfunc (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {\n\tctx := context.TODO()\n\tvals, err := qs.ValuesOf(ctx, []graph.Ref{v})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting NameOf %d: %w\", v, err)\n\t}\n\treturn vals[0], nil\n}\n\nfunc (qs *QuadStore) Quad(k graph.Ref) (quad.Quad, error) {\n\tkey, ok := k.(*proto.Primitive)\n\tif !ok {\n\t\treturn quad.Quad{}, fmt.Errorf(\"passed value was not a quad primitive: %T\", k)\n\t}\n\tctx := context.TODO()\n\tvar v quad.Quad\n\terr := kv.View(ctx, qs.db, func(tx kv.Tx) error {\n\t\tvar err error\n\t\tv, err = qs.primitiveToQuad(ctx, tx, key)\n\t\treturn err\n\t})\n\tif err == kv.ErrNotFound {\n\t\terr = nil\n\t}\n\tif err != nil {\n\t\terr = fmt.Errorf(\"error fetching quad %#v: %w\", key, err)\n\t}\n\treturn v, err\n}\n\nfunc (qs *QuadStore) primitiveToQuad(ctx context.Context, tx kv.Tx, p *proto.Primitive) (quad.Quad, error) {","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/kv/quadstore.go#L360-L396","documentation":"Quad(k) retrieves the quad for a given reference, but it requires the ref to be a *proto.Primitive — the concrete ref type this kv quadstore uses internally. If the caller passes any other graph.Ref implementation, the store cannot compute the KV key and returns this type assertion error. It is a programming/API-misuse guard, not a data problem.","triggerScenarios":"Calling QuadStore.Quad with a graph.Ref that is not *proto.Primitive — e.g. a ref from another backend, a plain quad.IRI/BNode ref, or a nil ref.","commonSituations":"Mixing refs between quadstore backends; constructing refs manually instead of getting them from this store's iterators; switching the store type (memory vs kv) while reusing persisted refs.","solutions":["Only pass *proto.Primitive refs obtained from this QuadStore (iterators, QuadIterator results)","Type-check before calling: if _, ok := r.(*proto.Primitive); !ok { handle }","Re-resolve the quad by its value instead of by ref if you only have an IRI/BNode","Avoid persisting refs across backends or store restarts"],"exampleFix":"// before\nq, err := qs.Quad(someIRIRef)\n// after\np, ok := someIRIRef.(*proto.Primitive)\nif !ok {\n    return fmt.Errorf(\"need a *proto.Primitive ref from this store\")\n}\nq, err := qs.Quad(p)","handlingStrategy":"type-guard","validationCode":"if p, ok := k.(*proto.Primitive); !ok || p == nil {\n    return errors.New(\"Quad requires a *proto.Primitive ref from this kv store\")\n}","typeGuard":"func toPrimitive(k graph.Ref) (*proto.Primitive, bool) {\n    p, ok := k.(*proto.Primitive)\n    if !ok || p == nil {\n        return nil, false\n    }\n    return p, true\n}","tryCatchPattern":null,"preventionTips":["Always fetch refs from this store's own iterators before calling Quad","Never mix refs between memory and kv backends","Guard every Quad call with a *proto.Primitive assertion"],"tags":["type-assertion","graph-ref","quadstore"],"backgroundTag":"type-mismatch","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}