{"record":{"id":"5e2841dc4333b75c","repo":"cayleygraph/cayley","slug":"unexpected-type-for-float-field-t","errorCode":null,"errorMessage":"unexpected type for float field: %T","messagePattern":"unexpected type for float field: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/nosql/quadstore.go","lineNumber":568,"sourceCode":"\t\t\tif vs, ok := d[fldValStrInt].(nosql.String); ok {\n\t\t\t\tiv := quad.Int(stoi(string(vs)))\n\t\t\t\treturn iv, nil\n\t\t\t}\n\t\t}\n\t\tvi, err := asInt(v)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn quad.Int(vi), nil\n\t} else if v, ok := d[fldValFloat]; ok {\n\t\tvar vf quad.Float\n\t\tswitch v := v.(type) {\n\t\tcase nosql.Int:\n\t\t\tvf = quad.Float(v)\n\t\tcase nosql.Float:\n\t\t\tvf = quad.Float(v)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unexpected type for float field: %T\", v)\n\t\t}\n\t\treturn vf, nil\n\t} else if v, ok := d[fldValBool]; ok {\n\t\tvar vb quad.Bool\n\t\tswitch v := v.(type) {\n\t\tcase nosql.Bool:\n\t\t\tvb = quad.Bool(v)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unexpected type for bool field: %T\", v)\n\t\t}\n\t\treturn vb, nil\n\t} else if v, ok := d[fldValTime]; ok {\n\t\tvar vt quad.Time\n\t\tswitch v := v.(type) {\n\t\tcase nosql.Time:\n\t\t\tvt = quad.Time(v)\n\t\tcase nosql.String:\n\t\t\tvar t time.Time","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/nosql/quadstore.go#L550-L586","documentation":"toQuadValue converts the float value field to quad.Float; this error is thrown when the stored fldValFloat field is neither nosql.Int nor nosql.Float. The value document's float slot holds an unexpected Go/nosql type, so the quad value cannot be reconstructed.","triggerScenarios":"Reading a quad value written as a float by an incompatible encoder that stored nosql.String/Bytes/Bool in the float field, or a corrupted/hand-edited document.","commonSituations":"Cross-version data migration (value encoding changes); custom import tools writing plain JSON numbers that the driver stores as string; corruption from a failed write.","solutions":["Log %T of the value to identify the stored type and the writer that produced it.","Re-import the affected data with the current Cayley version so floats are stored as nosql.Float.","Fix custom writers to encode numbers as nosql.Float (or nosql.Int).","Dump/re-load the quadstore to normalize value encodings if migration drift is suspected."],"exampleFix":"// before\ndefault:\n    return nil, fmt.Errorf(\"unexpected type for float field: %T\", v)\n// after\ncase nosql.String:\n    f, err := strconv.ParseFloat(string(v), 64)\n    if err != nil {\n        return nil, fmt.Errorf(\"float field not parseable: %w\", err)\n    }\n    vf = quad.Float(f)\ndefault:\n    return nil, fmt.Errorf(\"unexpected type for float field: %T\", v)","handlingStrategy":"type-guard","validationCode":"func isFloatLike(v nosql.Value) bool {\n    switch v.(type) {\n    case nosql.Int, nosql.Float:\n        return true\n    }\n    return false\n}","typeGuard":"func asFloatSafe(v interface{}) (quad.Float, bool) {\n    switch t := v.(type) {\n    case nosql.Int:\n        return quad.Float(t), true\n    case nosql.Float:\n        return quad.Float(t), true\n    }\n    return 0, false\n}","tryCatchPattern":"val, err := toQuadValue(opt, doc)\nif err != nil {\n    log.Printf(\"bad float field %T, skipping value: %v\", doc[fldValFloat], err)\n    return quad.Raw(\"\"), nil\n}","preventionTips":["Write floats as nosql.Float in importers","Re-import after cross-version migrations","Avoid string-encoded numbers in the float field"],"tags":["type-mismatch","nosql","float","cayley"],"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"}