cayleygraph/cayley · error

unmarshal value: %w

Error message

unmarshal value: %w

What it means

When a stored value is neither a plain string, bool, int, float, nor time, the SQL quadstore falls back to pquads.UnmarshalValue on the protobuf blob column to rebuild the quad.Value. If that protobuf blob cannot be unmarshaled, this wrapped error is returned.

Source

Thrown at graph/sql/quadstore.go:726

			val = quad.TypedString{
				Value: quad.String(unescapeNullByte(str.String)),
				Type:  quad.IRI(typ.String),
			}
		} else {
			val = quad.String(unescapeNullByte(str.String))
		}
	} else if vint.Valid {
		val = quad.Int(vint.Int64)
	} else if vbool.Valid {
		val = quad.Bool(vbool.Bool)
	} else if vfloat.Valid {
		val = quad.Float(vfloat.Float64)
	} else if *vtimeValid {
		val = quad.Time(vtimeTime.UTC())
	} else {
		qv, err := pquads.UnmarshalValue(data)
		if err != nil {
			return nil, fmt.Errorf("unmarshal value: %w", err)
		}
		val = qv
	}
	if val != nil {
		qs.ids.Put(hash.String(), val)
	}
	return val, nil
}

func (qs *QuadStore) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
	st := graph.Stats{
		Nodes: refs.Size{Exact: true},
		Quads: refs.Size{Exact: true},
	}
	qs.mu.RLock()
	st.Quads.Value = qs.quads
	st.Nodes.Value = qs.nodes
	qs.mu.RUnlock()

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Check the wrapped error to see if the blob is empty or malformed
  2. Verify the data was written by a compatible version of the quadstore/proto schema
  3. Re-import the affected data from source RDF/quads
  4. Delete corrupt rows and let the store rebuild from an authoritative dataset

Example fix

// before
// data column written by old schema
qs.NameOf(h) // unmarshal value: proto: wrong wireType ...
// after
// re-export and re-load data with matching cayley version before querying
Defensive patterns

Strategy: try-catch

Try / catch

val, err := qs.NameOf(h)
if err != nil && strings.Contains(err.Error(), "unmarshal value") {
    // treat row as corrupt: log hash, skip or trigger re-import
}

Prevention

When it happens

Trigger: The `data` protobuf column is empty, truncated, or written by an incompatible version whose protobuf schema differs; corrupt rows in the values table.

Common situations: Restoring a dump from an older/newer Cayley version with a changed proto schema; manual DB edits; interrupted writes leaving partial blobs.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


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