{"record":{"id":"7df973d7b3b124d7","repo":"cayleygraph/cayley","slug":"unexpected-type-for-bool-field-t","errorCode":null,"errorMessage":"unexpected type for bool field: %T","messagePattern":"unexpected type for bool field: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/nosql/quadstore.go","lineNumber":577,"sourceCode":"\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\n\t\t\tif err := t.UnmarshalJSON([]byte(`\"` + string(v) + `\"`)); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tvt = quad.Time(t)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unexpected type for bool field: %T\", v)\n\t\t}\n\t\treturn vt, nil\n\t}","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/nosql/quadstore.go#L559-L595","documentation":"toQuadValue converts the boolean value field to quad.Bool; this error is thrown when the stored fldValBool field is anything other than nosql.Bool. The boolean slot of the value document holds an unexpected type so the value cannot be reconstructed.","triggerScenarios":"Reading a boolean quad value whose document field was stored as String/Int/Bytes/Time by an incompatible writer, or a corrupted document.","commonSituations":"Migration between Cayley versions or NoSQL backends with different type mappings; custom tooling writing booleans as strings (\"true\"); hand-edited documents.","solutions":["Inspect %T of the stored value to find the real type.","Re-load the data through the current Cayley version so booleans are stored as nosql.Bool.","Fix custom importers to write nosql.Bool values.","Dump and re-import the store if widespread encoding drift is present."],"exampleFix":"// before\ndefault:\n    return nil, fmt.Errorf(\"unexpected type for bool field: %T\", v)\n// after\ncase nosql.String:\n    vb = quad.Bool(string(v) == \"true\")\ndefault:\n    return nil, fmt.Errorf(\"unexpected type for bool field: %T\", v)","handlingStrategy":"type-guard","validationCode":"func isBoolField(v nosql.Value) bool {\n    _, ok := v.(nosql.Bool)\n    return ok\n}","typeGuard":"func asBoolSafe(v interface{}) (quad.Bool, bool) {\n    b, ok := v.(nosql.Bool)\n    return quad.Bool(b), ok\n}","tryCatchPattern":"val, err := toQuadValue(opt, doc)\nif err != nil {\n    log.Printf(\"bad bool field %T, skipping value: %v\", doc[fldValBool], err)\n    return quad.Raw(\"\"), nil\n}","preventionTips":["Write booleans as nosql.Bool, not strings or ints","Normalize data through re-import after migrations","Avoid manual document edits"],"tags":["type-mismatch","nosql","bool","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"}