{"record":{"id":"da8d363fdbd46f48","repo":"dagger/dagger","slug":"interface-types-must-be-named-da8d36","errorCode":null,"errorMessage":"interface types must be named","messagePattern":"interface types must be named","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/templates/module_types.go","lineNumber":118,"sourceCode":"\t\t}\n\t\ttypeName := named.Obj().Name()\n\t\tif typeName == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"struct types must be named\")\n\t\t}\n\t\tmoduleName := \"\"\n\t\tif !ps.isDaggerGenerated(named.Obj()) {\n\t\t\tmoduleName = ps.moduleName\n\t\t}\n\t\treturn &parsedObjectTypeReference{\n\t\t\tname:       typeName,\n\t\t\tmoduleName: moduleName,\n\t\t\tisPtr:      isPtr,\n\t\t\tgoType:     named,\n\t\t}, nil\n\n\tcase *types.Interface:\n\t\tif named == nil {\n\t\t\treturn nil, fmt.Errorf(\"interface types must be named\")\n\t\t}\n\t\ttypeName := named.Obj().Name()\n\t\tif typeName == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"interface types must be named\")\n\t\t}\n\t\tmoduleName := \"\"\n\t\tif !ps.isDaggerGenerated(named.Obj()) {\n\t\t\tmoduleName = ps.moduleName\n\t\t}\n\t\treturn &parsedIfaceTypeReference{\n\t\t\tname:       typeName,\n\t\t\tmoduleName: moduleName,\n\t\t\tgoType:     named,\n\t\t}, nil\n\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported type for named type reference %T\", t)\n\t}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/templates/module_types.go#L100-L136","documentation":"When parseGoTypeReference encounters a Go interface type, it requires the interface to be wrapped in a *types.Named so codegen can reference it by name (Dagger interfaces become named SDK types). An anonymous interface type (interface{...} used directly) has named == nil and triggers \"interface types must be named\".","triggerScenarios":"A module function param, return, or object field typed as an anonymous interface literal (e.g. field someInterface, or var x interface{ Method() }), or an interface reached via recursion paths that pass named=nil (aliases, slices).","commonSituations":"Using `any`/interface{} placeholders that codegen can't name; embedding anonymous interfaces in module APIs; writing []interface{...} elements; adopting Dagger custom interfaces without giving them top-level names.","solutions":["Declare the interface as a named type: `type MyIface interface {...}` and use MyIface in signatures","Replace anonymous interface{} / any fields with concrete named types or dagger.JSON","For slices of interfaces, define a named interface element type: []MyIface","Regenerate with dagger develop after renaming so the SDK picks up the interface"],"exampleFix":"// before\nfunc Run(cb interface { Do() error }) error\n// after\ntype Callback interface { Do() error }\nfunc Run(cb Callback) error","handlingStrategy":"validation","validationCode":"// reject anonymous interfaces in module API signatures\nfunc noAnonIfaces(f *ast.FuncDecl) error {\n\tvar bad bool\n\tast.Inspect(f.Type, func(n ast.Node) bool {\n\t\tif it, ok := n.(*ast.InterfaceType); ok && len(it.Methods.List) >= 0 {\n\t\t\t// only flag unnamed contexts: params/results/fields, not top-level TypeSpecs\n\t\t\tbad = bad || !isInsideTypeSpec(n)\n\t\t}\n\t\treturn true\n\t})\n\tif bad { return fmt.Errorf(\"declare the interface as `type X interface{...}`\") }\n\treturn nil\n}","typeGuard":"func isAnonymousInterface(t ast.Expr) bool {\n\t_, ok := t.(*ast.InterfaceType)\n\treturn ok\n}","tryCatchPattern":"if err != nil && err.Error() == \"interface types must be named\" {\n\treturn fmt.Errorf(\"declare the interface at package level, e.g. `type MyIface interface{...}`\")\n}","preventionTips":["Give every Dagger-facing interface a top-level name","Avoid interface{} and any in module signatures; use dagger.JSON or concrete named types","For slice-of-interface fields, name the interface element type","Keep custom-interface implementations in the same module so codegen can name them"],"tags":["codegen","go","dagger","anonymous-interface"],"backgroundTag":"interface-type-must-be-named","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"}