dagger/dagger · error

failed to generate slice field type code: %w

Error message

failed to generate slice field type code: %w

What it means

During Dagger module Go codegen, when generating the concrete struct type for a slice field (e.g. []Foo or []*Foo), the codegen recursively generates the field type code for the slice's element type. If generating that element type code fails, the failure is wrapped with "failed to generate slice field type code". This is a wrapper error: the real cause is in the element type itself.

Source

Thrown at cmd/codegen/generator/go/templates/module_objects.go:484

			}

			s.Id(typeSpec.GoType().String())
		}

	case *parsedEnumTypeReference:
		if typeSpec.isPtr {
			s.Op("*")
		}
		if typeSpec.moduleName == "" {
			s.Id("dagger." + typeSpec.name)
		} else {
			s.Id(typeSpec.name)
		}

	case *parsedSliceType:
		fieldTypeCode, err := spec.concreteFieldTypeCode(typeSpec.underlying)
		if err != nil {
			return nil, fmt.Errorf("failed to generate slice field type code: %w", err)
		}
		s.Index().Add(fieldTypeCode)

	case *parsedObjectTypeReference:
		if typeSpec.isPtr {
			s.Op("*")
		}
		s.Id(typeName(typeSpec))

	case *parsedIfaceTypeReference:
		s.Op("*").Id(concreteIfaceImplName(typeSpec))

	default:
		return nil, fmt.Errorf("unsupported concrete field type %T", typeSpec)
	}

	return s, nil
}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Read the wrapped cause (%w) below this message in the codegen output to find the actual unsupported element type
  2. Simplify the field's element type to a supported one: primitive, enum, named object struct, or named interface
  3. Ensure slice elements are named types (avoid anonymous structs or maps as element types)
  4. Update the Dagger CLI/SDK, as newer versions support more concrete field types

Example fix

// before (module code)
Field []map[string]string
// after
Field []string
Defensive patterns

Strategy: validation

Validate before calling

// before running codegen, check slice fields only contain supported named types
type checker struct{ err error }
func (c *checker) Visit(n ast.Node) ast.Visitor {
	if ft, ok := n.(*ast.Field); ok && ft.Type != nil {
		if !supportedFieldType(ft.Type) {
			c.err = fmt.Errorf("slice field element %s is not a supported named type", ft.Type)
		}
	}
	return c
}

Type guard

func isSupportedElemType(t ast.Expr) bool {
	switch e := t.(type) {
	case *ast.Ident: return true
	case *ast.StarExpr: return isSupportedElemType(e.X)
	case *ast.ArrayType: return isSupportedElemType(e.Elt)
	default: return false
	}
}

Try / catch

if err := generateModule(); err != nil {
	var wrapped interface{ Unwrap() error }
	if errors.As(err, &target) { log.Fatalf("codegen: root cause: %v", errors.Unwrap(err)) }
}

Prevention

When it happens

Trigger: Running dagger develop/codegen on a module whose object has a slice field whose element type causes concreteFieldTypeCode to hit its default branch (an unsupported ParsedType implementation) or another nested failure (e.g. a nested slice of an unsupported type).

Common situations: A dagger.ObjectStruct field like []SomeIface or [][]SomeUnsupportedType where the element resolves to a ParsedType variant the concrete-struct generator doesn't handle; usually encountered right after adding a new field type to a module or after a Dagger SDK version upgrade changed the parsed type set.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/afa5a10db8c3eda3. Report an issue: GitHub.