dagger/dagger · error
nested structs are not supported
Error message
nested structs are not supported
What it means
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'.
Source
Thrown at cmd/codegen/generator/go/templates/module_funcs.go:407
docComment, lineComment := ps.commentForFuncField(fnDecl, paramFields, i)
spec, err := ps.parseParamSpecVar(params.At(i), paramFields[i], docComment.Text(), lineComment.Text())
if err != nil {
return nil, err
}
if spec.isContext {
return nil, fmt.Errorf("unexpected context type for arg %s", spec.name)
}
if sig.Variadic() && i == params.Len()-1 {
spec.variadic = true
}
specs = append(specs, spec)
}
return specs, nil
}
func (ps *parseState) parseParamSpecVar(field *types.Var, astField *ast.Field, docComment string, lineComment string) (paramSpec, error) {
if _, ok := field.Type().(*types.Struct); ok {
return paramSpec{}, fmt.Errorf("nested structs are not supported")
}
paramType := field.Type()
baseType := paramType
isPtr := false
for {
ptr, ok := baseType.(*types.Pointer)
if !ok {
break
}
isPtr = true
baseType = ptr.Elem()
}
docPragmas, docComment := parsePragmaComment(docComment)
linePragmas, lineComment := parsePragmaComment(lineComment)
comment := strings.TrimSpace(docComment)
if comment == "" {View on GitHub (pinned to 82ba2681db)
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
Example fix
// before
func (m *Mod) Foo(ctx context.Context, args struct {
Inner struct { X string }
}) error
// after
type Inner struct { X string }
func (m *Mod) Foo(ctx context.Context, args struct {
Inner Inner
}) error Defensive patterns
Strategy: validation
Validate before calling
// reject anonymous struct fields inside inline-struct args
// bad: args struct{ Inner struct{ X string } }
// good: type Inner struct{ X string }; args struct{ Inner Inner } Try / catch
if err := runCodegen(); err != nil {
if strings.Contains(err.Error(), "nested structs are not supported") {
// hoist the nested anonymous struct to a named type
}
} Prevention
- Name every struct used as a nested field
- Keep argument structs one level deep
- Flatten configuration objects
When it happens
Trigger: 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 } }.
Common situations: Defining deeply nested inline config objects in one signature; pasting JSON-shaped nested structures into Go function args.
Related errors
- could not encode default value %q: %w
- expected struct type for %s
- unexpected context type in inline field %s
- unexpected context type for arg %s
- defaultPath pragma %q, must be a valid string
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/d53b86b6b7930cf6.
Report an issue: GitHub.