{"record":{"id":"3d1aad70d81dd43f","repo":"cayleygraph/cayley","slug":"unexpected-token-t","errorCode":null,"errorMessage":"unexpected token: %T","messagePattern":"unexpected token: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/sql/quadstore.go","lineNumber":632,"sourceCode":"\treturn nt.Time, nil\n}\n\nfunc (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {\n\tif v == nil {\n\t\treturn nil, nil\n\t} else if v, ok := v.(refs.PreFetchedValue); ok {\n\t\treturn v.NameOf(), nil\n\t}\n\tvar hash NodeHash\n\tswitch h := v.(type) {\n\tcase refs.PreFetchedValue:\n\t\treturn h.NameOf(), nil\n\tcase NodeHash:\n\t\thash = h\n\tcase refs.ValueHash:\n\t\thash = NodeHash{h}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unexpected token: %T\", v)\n\t}\n\tif !hash.Valid() {\n\t\treturn nil, nil\n\t}\n\tif val, ok := qs.ids.Get(hash.String()); ok {\n\t\treturn val.(quad.Value), nil\n\t}\n\tquery := `SELECT\n\t\tvalue,\n\t\tvalue_string,\n\t\tdatatype,\n\t\tlanguage,\n\t\tiri,\n\t\tbnode,\n\t\tvalue_int,\n\t\tvalue_bool,\n\t\tvalue_float,\n\t\tvalue_time","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/sql/quadstore.go#L614-L650","documentation":"NameOf resolves a stored node token (NodeHash, refs.ValueHash, or a quad.Value wrapper) back to its quad.Value. If the argument's concrete type isn't one of the recognized token types, this error is returned. It usually indicates a hash-vs-value mismatch in iterator plumbing.","triggerScenarios":"Passing a value of an unexpected type (e.g. a plain string, quad.IRI, or a different hash type) to qs.NameOf instead of NodeHash/refs.ValueHash/wrapped values; custom iterators feeding unsupported token types.","commonSituations":"Writing custom iterators or resolvers over the SQL store that emit raw quad values where hashes are expected; API drift between quadstore versions changing the token type contract.","solutions":["Ensure only NodeHash or refs.ValueHash values are passed to NameOf","If you hold a quad.Value, use the appropriate hash conversion (e.g. qs.ValueOf) before lookup","Check the type of the token with %T before calling NameOf","Update custom iterator code to match the current QuadStore token API"],"exampleFix":"// before\nval, _ := qs.NameOf(quad.IRI(\"http://example.com\"))\n// after\nh := qs.ValueOf(quad.IRI(\"http://example.com\"))\nval, _ := qs.NameOf(h)","handlingStrategy":"type-guard","validationCode":"func isNodeToken(v interface{}) bool {\n    switch v.(type) {\n    case graph.NodeHash, refs.ValueHash, quad.Value:\n        return true\n    }\n    return false\n}","typeGuard":"switch t := v.(type) {\ncase NodeHash, refs.ValueHash:\n    // safe to call NameOf\ndefault:\n    return fmt.Errorf(\"NameOf requires NodeHash/refs.ValueHash, got %T\", t)\n}","tryCatchPattern":"val, err := qs.NameOf(tok)\nif err != nil && strings.Contains(err.Error(), \"unexpected token\") {\n    tok = qs.ValueOf(v) // convert then retry\n    val, err = qs.NameOf(tok)\n}","preventionTips":["Only feed hashes obtained from ValueOf/iterator results into NameOf","Check %T of tokens when writing custom iterators","Keep custom iterator code in sync with the quadstore token API"],"tags":["sql","quadstore","type-mismatch"],"backgroundTag":"type-mismatch","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"}