{"record":{"id":"d53b86b6b7930cf6","repo":"dagger/dagger","slug":"nested-structs-are-not-supported","errorCode":null,"errorMessage":"nested structs are not supported","messagePattern":"nested structs are not supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/templates/module_funcs.go","lineNumber":407,"sourceCode":"\t\tdocComment, lineComment := ps.commentForFuncField(fnDecl, paramFields, i)\n\t\tspec, err := ps.parseParamSpecVar(params.At(i), paramFields[i], docComment.Text(), lineComment.Text())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif spec.isContext {\n\t\t\treturn nil, fmt.Errorf(\"unexpected context type for arg %s\", spec.name)\n\t\t}\n\t\tif sig.Variadic() && i == params.Len()-1 {\n\t\t\tspec.variadic = true\n\t\t}\n\t\tspecs = append(specs, spec)\n\t}\n\treturn specs, nil\n}\n\nfunc (ps *parseState) parseParamSpecVar(field *types.Var, astField *ast.Field, docComment string, lineComment string) (paramSpec, error) {\n\tif _, ok := field.Type().(*types.Struct); ok {\n\t\treturn paramSpec{}, fmt.Errorf(\"nested structs are not supported\")\n\t}\n\n\tparamType := field.Type()\n\tbaseType := paramType\n\tisPtr := false\n\tfor {\n\t\tptr, ok := baseType.(*types.Pointer)\n\t\tif !ok {\n\t\t\tbreak\n\t\t}\n\t\tisPtr = true\n\t\tbaseType = ptr.Elem()\n\t}\n\n\tdocPragmas, docComment := parsePragmaComment(docComment)\n\tlinePragmas, lineComment := parsePragmaComment(lineComment)\n\tcomment := strings.TrimSpace(docComment)\n\tif comment == \"\" {","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/templates/module_funcs.go#L389-L425","documentation":"Dagger function arguments may not be plain (unnamed) struct types nested inside another struct or anonymous-struct argument; only flat fields are supported. When parseParamSpecVar sees a field whose type is a *types.Struct it aborts with 'nested structs are not supported'.","triggerScenarios":"A field inside an inline-struct argument (or an argument) whose declared type is an anonymous struct literal, e.g. struct{ Inner struct{ X string } }.","commonSituations":"Defining deeply nested inline config objects in one signature; pasting JSON-shaped nested structures into Go function args.","solutions":["Extract the inner struct into a named type and reference it by name","Flatten the nested fields into the top-level struct","Restructure the API into multiple function arguments"],"exampleFix":"// before\nfunc (m *Mod) Foo(ctx context.Context, args struct {\n  Inner struct { X string }\n}) error\n\n// after\ntype Inner struct { X string }\nfunc (m *Mod) Foo(ctx context.Context, args struct {\n  Inner Inner\n}) error","handlingStrategy":"validation","validationCode":"// reject anonymous struct fields inside inline-struct args\n// bad:  args struct{ Inner struct{ X string } }\n// good: type Inner struct{ X string }; args struct{ Inner Inner }","typeGuard":null,"tryCatchPattern":"if err := runCodegen(); err != nil {\n    if strings.Contains(err.Error(), \"nested structs are not supported\") {\n        // hoist the nested anonymous struct to a named type\n    }\n}","preventionTips":["Name every struct used as a nested field","Keep argument structs one level deep","Flatten configuration objects"],"tags":["codegen","go","dagger-module","nested-struct"],"backgroundTag":"nested-struct-unsupported","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"}