{"record":{"id":"1d2f862163c14bc7","repo":"dagger/dagger","slug":"failed-to-generate-type-def-code-for-s-w","errorCode":null,"errorMessage":"failed to generate type def code for %s: %w","messagePattern":"failed to generate type def code for (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/templates/modules.go","lineNumber":163,"sourceCode":"\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\tStructVisitor: func(ps *parseState, named *types.Named, obj *types.TypeName, objTypeSpec *parsedObjectType, strct *types.Struct) error {\n\t\t\t\tif err := ps.fillObjectFunctionCases(named, objFunctionCases); err != nil {\n\t\t\t\t\t// errors indicate an internal problem rather than something w/ user code, so error instead\n\t\t\t\t\treturn fmt.Errorf(\"failed to generate function cases for %s: %w\", obj.Name(), err)\n\t\t\t\t}\n\n\t\t\t\t// Add the object to the module\n\t\t\t\timplCode, err := objTypeSpec.ImplementationCode()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to generate json method code for %s: %w\", obj.Name(), err)\n\t\t\t\t}\n\t\t\t\timplementationCode.Add(implCode).Line()\n\n\t\t\t\tobjTypeDefCode, err := objTypeSpec.TypeDefCode()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to generate type def code for %s: %w\", obj.Name(), err)\n\t\t\t\t}\n\t\t\t\tcreateMod = dotLine(createMod, \"WithObject\").Call(Add(Line(), objTypeDefCode))\n\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\tIfaceVisitor: func(ps *parseState, named *types.Named, obj *types.TypeName, ifaceTypeSpec *parsedIfaceType, iface *types.Interface) error {\n\t\t\t\t// Add the iface to the module\n\t\t\t\timplCode, err := ifaceTypeSpec.ImplementationCode()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to generate concrete struct code for %s: %w\", obj.Name(), err)\n\t\t\t\t}\n\t\t\t\timplementationCode.Add(implCode).Line()\n\n\t\t\t\tifaceTypeDefCode, err := ifaceTypeSpec.TypeDefCode()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to generate type def code for %s: %w\", obj.Name(), err)\n\t\t\t\t}\n\t\t\t\tcreateMod = dotLine(createMod, \"WithInterface\").Call(Add(Line(), ifaceTypeDefCode))","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/templates/modules.go#L145-L181","documentation":"Wrapping error from the StructVisitor in moduleMainSrc: after successfully generating implementation code, producing the object's TypeDefCode (the dag.TypeDef().WithObject(...) registration statement) failed. The object name is included; the true cause is wrapped with %w and comes from the type's TypeDef generation.","triggerScenarios":"objTypeSpec.TypeDefCode() errors while building the TypeDef for a module object — usually a field whose type reference cannot be converted to a TypeDef (unsupported basic type, anonymous composite, nested failure via slices).","commonSituations":"Objects containing fields with exotic Go types, deeply nested unsupported composites, or broken references to types from dependent modules.","solutions":["Read the wrapped cause to identify the failing field or sub-type.","Change the offending field to a supported Dagger type (named struct, primitive, slice, enum, scalar).","Regenerate dagger.gen.go via `dagger develop` and confirm the module compiles; upgrade CLI/SDK if this persists on valid code."],"exampleFix":"// before\ntype Cache struct {\n\tEntries map[string]Entry\n}\n\n// after\ntype Cache struct {\n\tEntries []Entry // or []EntryKeyVal with Key/Value fields\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate that all object field types map to Dagger TypeDef kinds.\nfunc validateTypeDefFields(t reflect.Type) error {\n\tfor i := 0; i < t.NumField(); i++ {\n\t\tft := t.Field(i).Type\n\t\tif ft.Kind() == reflect.Map || ft.Kind() == reflect.Chan || ft.Kind() == reflect.Func {\n\t\t\treturn fmt.Errorf(\"%s.%s (%v) has no TypeDef mapping\", t.Name(), t.Field(i).Name, ft)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := codegen(); err != nil && strings.Contains(err.Error(), \"failed to generate type def code\") {\n\tlog.Fatalf(\"typedef generation failed: %v\", errors.Unwrap(err))\n}","preventionTips":["Replace maps and other unmappable composites with slices of key/value structs.","Keep referenced dependency-module types loadable and up to date.","Unwrap the %w chain to identify the exact failing field before editing."],"tags":["go","codegen","dagger-module","type-def"],"backgroundTag":"codegen-type-def-failure","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}