{"record":{"id":"807d46478f15411c","repo":"cayleygraph/cayley","slug":"load-anonymous-field-s-failed-v","errorCode":null,"errorMessage":"load anonymous field %s failed: %v","messagePattern":"load anonymous field (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/loader.go","lineNumber":337,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor i := 0; i < rt.NumField(); i++ {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\t\tf := rt.Field(i)\n\t\tname := f.Name\n\t\tif err := checkFieldType(f.Type); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdf := dst.Field(i)\n\t\tif f.Anonymous {\n\t\t\tif err := l.loadToValue(ctx, df, depth, m, tagPref+name+\".\"); err != nil {\n\t\t\t\treturn fmt.Errorf(\"load anonymous field %s failed: %v\", f.Name, err)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\trules := fields[tagPref+name]\n\t\tif rules == nil {\n\t\t\tcontinue\n\t\t}\n\t\tarr, ok := m[tagPref+name]\n\t\tif !ok || len(arr) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tft := f.Type\n\t\tnative := isNative(ft)\n\t\tptr := ft.Kind() == reflect.Ptr\n\t\tfor ft.Kind() == reflect.Ptr || ft.Kind() == reflect.Slice {\n\t\t\tft = ft.Elem()\n\t\t\tnative = native || isNative(ft)\n\t\t\tswitch ft.Kind() {","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/loader.go#L319-L355","documentation":"When a struct embeds an anonymous field, the loader recursively loads it into the embedded value. If that recursive loadToValue fails, the error is wrapped as \"load anonymous field %s failed: %v\", preserving the embedded field name and the underlying cause.","triggerScenarios":"Loading into a struct with an embedded (anonymous) struct field whose own load fails — e.g. the embedded type is not a struct after deref, or its fields fail conversion.","commonSituations":"Embedding non-struct types (e.g. embedded interfaces or primitives) expected to be schema-mapped; the embedded struct's fields don't match stored quad values; renamed/removed schema tags after refactor.","solutions":["Read the wrapped %v cause first — it names the real failure (struct expected, conversion failed, etc.).","Ensure the anonymous field's type is a struct (or pointer to struct).","Fix the embedded struct's field tags/types to match the stored quad values."],"exampleFix":"// before\ntype Person struct {\n\tName string // not embedded issue\n\tMeta // embedded interface -> fails\n}\n// after\ntype Person struct {\n\tName string\n\tMeta MetaInfo // embedded struct type: type MetaInfo struct{ ... }\n}","handlingStrategy":"try-catch","validationCode":"for i := 0; i < reflect.TypeOf(dst).Elem().NumField(); i++ {\n    f := reflect.TypeOf(dst).Elem().Field(i)\n    if f.Anonymous && f.Type.Kind() != reflect.Struct && f.Type.Kind() != reflect.Ptr {\n        return fmt.Errorf(\"embedded field %s must be struct-based\", f.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := c.LoadTo(ctx, qs, &obj, id); err != nil {\n    var wrapped string = err.Error()\n    if strings.Contains(wrapped, \"load anonymous field\") {\n        cause := strings.SplitN(wrapped, \"failed: \", 2)\n        // inspect cause[1] for the inner failure and fix the embedded struct\n    }\n    return err\n}","preventionTips":["Only embed structs (or pointers to structs) in schema-mapped types.","Test loading of every embedded struct in unit tests.","Avoid embedding interfaces in schema types."],"tags":["go","reflection","struct-embedding","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-14T00:17:10.932Z"}