{"record":{"id":"c53f9f4164967252","repo":"cayleygraph/cayley","slug":"error-getting-nameof-d-w","errorCode":null,"errorMessage":"error getting NameOf %d: %w","messagePattern":"error getting NameOf (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/kv/quadstore.go","lineNumber":370,"sourceCode":"\t\t\tvalue, err := qs.resolveQuadValue(ctx, tx, node)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tvalues[i] = Int64Value(value)\n\t\t}\n\t\treturn nil\n\t})\n\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","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/kv/quadstore.go#L352-L388","documentation":"NameOf resolves a single graph.Ref to its quad.Value. If the underlying ValuesOf call fails (including the 'unknown type of graph.Ref' case above), the failure is wrapped with the ref for context and returned. The message carries the numeric ref id, which helps identify stale or invalid references.","triggerScenarios":"Calling QuadStore.NameOf with a ref the store cannot resolve: a ref of unexpected type (triggering error 56), or when the KV read for the primitive fails (not found, DB error, corruption).","commonSituations":"Using a ref from a stale iterator after the store changed; passing refs from a different backend; database read errors during node-name resolution.","solutions":["Inspect the wrapped cause (%w) to determine whether the ref type was wrong or the KV read failed","Ensure the ref originated from this QuadStore instance and is still valid","Re-fetch the ref via a fresh query/iterator instead of reusing a cached value","If the KV read fails persistently, check DB integrity or rebuild the store"],"exampleFix":"// before: reusing a stale ref\nname, err := qs.NameOf(staleRef)\n// after: verify origin and handle the wrapped error\nif _, ok := staleRef.(*proto.Primitive); !ok {\n    return fmt.Errorf(\"ref not from this store\")\n}\nname, err := qs.NameOf(staleRef)","handlingStrategy":"try-catch","validationCode":"if r == nil {\n    return errors.New(\"nil graph.Ref passed to NameOf\")\n}\nif _, ok := r.(*proto.Primitive); !ok {\n    return errors.New(\"ref is not from this kv quadstore\")\n}","typeGuard":"func isPrimitiveRef(r graph.Ref) (*proto.Primitive, bool) {\n    p, ok := r.(*proto.Primitive)\n    return p, ok\n}","tryCatchPattern":"name, err := qs.NameOf(ref)\nif err != nil {\n    var cause error\n    errors.As(err, &cause) // inspect wrapped cause: bad ref type vs KV failure\n    return fmt.Errorf(\"cannot resolve name for ref: %w\", err)\n}","preventionTips":["Check the wrapped error chain to distinguish ref-type errors from storage errors","Keep ref lifetime tied to the store instance that produced it","Refresh refs after any write/delete that may invalidate them"],"tags":["name-resolution","graph-ref","error-wrapping"],"backgroundTag":"entity-not-found","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"}