cayleygraph/cayley · error

error getting NameOf %d: %w

Error message

error getting NameOf %d: %w

What it means

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.

Source

Thrown at graph/kv/quadstore.go:370

			value, err := qs.resolveQuadValue(ctx, tx, node)
			if err != nil {
				return err
			}
			values[i] = Int64Value(value)
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return values, nil
}

func (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {
	ctx := context.TODO()
	vals, err := qs.ValuesOf(ctx, []graph.Ref{v})
	if err != nil {
		return nil, fmt.Errorf("error getting NameOf %d: %w", v, err)
	}
	return vals[0], nil
}

func (qs *QuadStore) Quad(k graph.Ref) (quad.Quad, error) {
	key, ok := k.(*proto.Primitive)
	if !ok {
		return quad.Quad{}, fmt.Errorf("passed value was not a quad primitive: %T", k)
	}
	ctx := context.TODO()
	var v quad.Quad
	err := kv.View(ctx, qs.db, func(tx kv.Tx) error {
		var err error
		v, err = qs.primitiveToQuad(ctx, tx, key)
		return err
	})
	if err == kv.ErrNotFound {
		err = nil

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Inspect the wrapped cause (%w) to determine whether the ref type was wrong or the KV read failed
  2. Ensure the ref originated from this QuadStore instance and is still valid
  3. Re-fetch the ref via a fresh query/iterator instead of reusing a cached value
  4. If the KV read fails persistently, check DB integrity or rebuild the store

Example fix

// before: reusing a stale ref
name, err := qs.NameOf(staleRef)
// after: verify origin and handle the wrapped error
if _, ok := staleRef.(*proto.Primitive); !ok {
    return fmt.Errorf("ref not from this store")
}
name, err := qs.NameOf(staleRef)
Defensive patterns

Strategy: try-catch

Validate before calling

if r == nil {
    return errors.New("nil graph.Ref passed to NameOf")
}
if _, ok := r.(*proto.Primitive); !ok {
    return errors.New("ref is not from this kv quadstore")
}

Type guard

func isPrimitiveRef(r graph.Ref) (*proto.Primitive, bool) {
    p, ok := r.(*proto.Primitive)
    return p, ok
}

Try / catch

name, err := qs.NameOf(ref)
if err != nil {
    var cause error
    errors.As(err, &cause) // inspect wrapped cause: bad ref type vs KV failure
    return fmt.Errorf("cannot resolve name for ref: %w", err)
}

Prevention

When it happens

Trigger: 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).

Common situations: Using a ref from a stale iterator after the store changed; passing refs from a different backend; database read errors during node-name resolution.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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