cayleygraph/cayley · error

cannot find quad in query output (columns: )

Error message

cannot find quad %v in query output (columns: %v)

What it means

In scanValue, when the iterator expects a full quad (multiple column indexes in it.cind), each quad direction (subject/predicate/object/label) must map to a query output column. This error means a required direction column is missing from the SELECT result, so the quad cannot be reconstructed. It is stored in it.err and aborts the scan.

Solutions

  1. Inspect the printed columns list and ensure your Select requests a column for every quad direction used.
  2. Build Selects via the library's helper methods rather than hand-crafting column lists.
  3. Check for version mismatches between the store schema and the library expecting per-direction columns.
Defensive patterns

Strategy: validation

Try / catch

for it.Next(ctx) { }
if it.Err() != nil {
    if strings.Contains(it.Err().Error(), "cannot find quad") {
        // rebuild the Select with all quad direction columns
    }
}

Prevention

When it happens

Trigger: Running a Next/NextPath/Contains on a SQL iterator built with a Select that requests quad directions, where the query result columns (it.cols) lack a column for one of the directions.

Common situations: Custom or hand-built Select statements whose column set doesn't match the directions the iterator expects; schema/column aliasing changes after an upgrade; queries optimized away a direction.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at graph/sql/iterator.go:198

	for i := range pointers {
		pointers[i] = &nodes[i]
	}
	if err := r.Scan(pointers...); err != nil {
		it.err = err
		return false
	}
	it.tags = make(map[string]graph.Ref)
	for i, name := range it.cols {
		if !strings.Contains(name, tagPref) {
			it.tags[name] = nodes[i].ValueHash
		}
	}
	if len(it.cind) > 1 {
		var q QuadHashes
		for _, d := range quad.Directions {
			i, ok := it.cind[d]
			if !ok {
				it.err = fmt.Errorf("cannot find quad %v in query output (columns: %v)", d, it.cols)
				return false
			}
			q.Set(d, nodes[i].ValueHash)
		}
		it.res = q
		return true
	}
	i, ok := it.cind[quad.Any]
	if !ok {
		it.err = fmt.Errorf("cannot find node hash in query output (columns: %v, cind: %v)", it.cols, it.cind)
		return false
	}
	it.res = nodes[i]
	return true
}

func (it *iteratorBase) Err() error {
	return it.err

View on GitHub (pinned to 81dcd7d73e)