cayleygraph/cayley · error

unknown value format: %T

Error message

unknown value format: %T

What it means

toQuadValue converts a stored nosql document back into a quad.Value. The document's value field ("str") must hold a nosql.String; if it holds any other type (nil, nosql.Bool, a number, etc.) the document is corrupt or was written by an incompatible writer, so this error is thrown.

Source

Thrown at graph/nosql/quadstore.go:598

	} else if v, ok := d[fldValTime]; ok {
		var vt quad.Time
		switch v := v.(type) {
		case nosql.Time:
			vt = quad.Time(v)
		case nosql.String:
			var t time.Time
			if err := t.UnmarshalJSON([]byte(`"` + string(v) + `"`)); err != nil {
				return nil, err
			}
			vt = quad.Time(t)
		default:
			return nil, fmt.Errorf("unexpected type for bool field: %T", v)
		}
		return vt, nil
	}
	vs, ok := d[fldValData].(nosql.String)
	if !ok {
		return nil, fmt.Errorf("unknown value format: %T", d[fldValData])
	}
	if len(d) == 1 {
		return quad.String(vs), nil
	}
	if ok, _ := d[fldIRI].(nosql.Bool); ok {
		return quad.IRI(vs), nil
	} else if ok, _ := d[fldBNode].(nosql.Bool); ok {
		return quad.BNode(vs), nil
	} else if typ, ok := d[fldType].(nosql.String); ok {
		return quad.TypedString{Value: quad.String(vs), Type: quad.IRI(typ)}, nil
	} else if typ, ok := d[fldLang].(nosql.String); ok {
		return quad.LangString{Value: quad.String(vs), Lang: string(typ)}, nil
	}
	return nil, fmt.Errorf("unsupported value: %#v", d)
}

func (qs *QuadStore) Quad(val graph.Ref) (quad.Quad, error) {
	h := val.(QuadHash)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Inspect the offending document and check which type the "str" field actually holds
  2. Re-import the source data (nquads/JSONL) into a fresh store to rebuild the document
  3. Verify the store was written and read with the same Cayley version
  4. If handling externally-produced documents, validate document shape before calling toQuadValue

Example fix

// before: blindly converting a hash read from disk
v, err := NameOf(h)
// after: validate the document field first
if _, ok := doc[fldValData].(nosql.String); !ok {
    return fmt.Errorf("skipping malformed document %v", doc)
}
v, err := NameOf(h)
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := doc["str"].(nosql.String); !ok { return fmt.Errorf("document %v has no string value", doc) }

Type guard

func isStringDoc(d map[string]interface{}) bool { _, ok := d[fldValData].(nosql.String); return ok }

Try / catch

v, err := toQuadValue(doc)
if err != nil {
    log.Warnf("skipping malformed document: %v", err)
    return nil // or fallback
}

Prevention

When it happens

Trigger: Calling NameOf (or Quad) on a QuadHash whose underlying document lacks a nosql.String under the "str" key — typically a corrupted, hand-edited, or foreign document in the nosql backend.

Common situations: Data written by a different Cayley/nosql version, manual edits to a KV store (bolt/leveldb), or deserialization of a document that never went through toDocumentValue.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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