{"record":{"id":"95d91c0be90990c4","repo":"cayleygraph/cayley","slug":"field-s-v","errorCode":null,"errorMessage":"field %s: %v","messagePattern":"field (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/loader.go","lineNumber":396,"sourceCode":"\t\t\t\tsv = reflect.New(ft).Elem()\n\t\t\t\terr := l.loadIteratorToDepth(ctx, sv, depth-1, iterator.NewFixed(fv))\n\t\t\t\tif err == errRequiredFieldIsMissing {\n\t\t\t\t\tcontinue\n\t\t\t\t} else if err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfv, err := l.qs.NameOf(fv)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tif fv == nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tsv = reflect.ValueOf(fv)\n\t\t\t}\n\t\t\tif err := DefaultConverter.SetValue(df, sv); err != nil {\n\t\t\t\treturn fmt.Errorf(\"field %s: %v\", f.Name, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (l *loader) iteratorForType(ctx context.Context, root iterator.Shape, rt reflect.Type, rootOnly bool) (iterator.Shape, error) {\n\tp, err := l.makePathForType(rt, \"\", rootOnly)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn l.iteratorFromPath(ctx, root, p)\n}\n\nfunc mergeMap(dst map[string][]graph.Ref, m map[string]graph.Ref) {\nloop:\n\tfor k, v := range m {\n\t\tsl := dst[k]","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/loader.go#L378-L414","documentation":"When setting a struct field from a graph value, DefaultConverter.SetValue failed. The loader wraps that failure as \"field %s: %v\" so the developer knows which struct field could not be populated and why (typically a type conversion failure).","triggerScenarios":"A quad value's runtime type does not match the destination field type — e.g. an IRI or string in the graph being converted into an int/bool/float field, or a time field fed a non-time value.","commonSituations":"Schema drift: the graph stores strings but the struct field was changed to int; missing custom Converter for a custom type; loading RDF data with unexpected value kinds into strongly typed structs.","solutions":["Check the wrapped inner error for the exact conversion failure and align the struct field type with the stored quad value type.","Register a custom converter (schema.RegisterConverter) for the custom/complex field type.","Validate/normalize data in the store, or make the field a string/interface{} and convert manually after load."],"exampleFix":"// before\ntype P struct{ Age int `quad:\"age\"` } // store holds \"42\" as string\n// after\ntype P struct{ Age string `quad:\"age\"` }\n// or register a converter:\nschema.RegisterConverter(0, converterFunc(func(v quad.Value, out reflect.Value) (interface{}, error) {...}))","handlingStrategy":"try-catch","validationCode":"// check field types vs expected quad value kinds before load\nt := reflect.TypeOf(Person{})\nf, _ := t.FieldByName(\"Age\")\nif f.Type.Kind() != reflect.String && f.Type.Kind() != reflect.Int {\n    return errors.New(\"field type not convertible from stored quad value\")\n}","typeGuard":null,"tryCatchPattern":"if err := c.LoadTo(ctx, qs, &obj, id); err != nil {\n    if strings.Contains(err.Error(), \"field \") {\n        // extract field name from \"field <name>: <cause>\" and align types\n        return fmt.Errorf(\"load conversion failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Match struct field types to the value kinds actually stored in the graph.","Register custom converters for complex field types.","Store strongly typed values via schema.WriteAsQuads so reads convert cleanly."],"tags":["go","reflection","type-conversion","schema"],"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"}