dagger/dagger · error
failed to parse field type: %w
Error message
failed to parse field type: %w
What it means
Wraps a failure from parseGoTypeReference while resolving the type of an exported struct field of a Dagger object. Dagger must map every field to a GraphQL type; if the field's Go type is not representable (unsupported generic, unexported dependency type, channel, func, etc.) the inner error is wrapped as 'failed to parse field type'.
Source
Thrown at cmd/codegen/generator/go/templates/module_objects.go:109
return nil, fmt.Errorf("expected type spec, got %T", astSpec)
}
astStructType, ok := astTypeSpec.Type.(*ast.StructType)
if !ok {
return nil, fmt.Errorf("expected type spec to be a struct, got %T", astTypeSpec.Type)
}
// Fill out the static fields of the struct (if any)
astFields := unpackASTFields(astStructType.Fields)
for i := range t.NumFields() {
field := t.Field(i)
if !field.Exported() {
continue
}
fieldSpec := &fieldSpec{goType: field.Type()}
fieldSpec.typeSpec, err = ps.parseGoTypeReference(fieldSpec.goType, nil, false)
if err != nil {
return nil, fmt.Errorf("failed to parse field type: %w", err)
}
fieldSpec.goName = field.Name()
fieldSpec.name = fieldSpec.goName
// override the name with the json tag if it was set - otherwise, we
// end up asking for a name that we won't unmarshal correctly
tag := reflect.StructTag(t.Tag(i))
if dt := tag.Get("json"); dt != "" {
namePart, _, _ := strings.Cut(dt, ",")
if namePart == "-" {
continue
}
if namePart != "" {
fieldSpec.name = namePart
}
}
View on GitHub (pinned to 82ba2681db)
Solutions
- Read the wrapped inner error to see which field/type was rejected.
- Change the field to a supported Dagger type (primitive, string-enum, list, another Dagger object, or ID scalar).
- Make unsupported fields unexported (lowercase) so they are skipped by codegen.
- Use a `json:"-"` tag to exclude an exported field from the schema.
- For complex types, store them unexported and expose accessor methods instead.
Example fix
// before
type Cache struct {
Ch chan string
}
// after
type Cache struct {
Keys []string
ch chan string // unexported, ignored by codegen
} Defensive patterns
Strategy: validation
Validate before calling
// audit exported fields of Dagger objects for unsupported types: // go vet ./... // plus grep for obvious offenders: // grep -R -E '^\s+[A-Z][A-Za-z]*\s+(chan|func<|func\()' --include='*.go' .
Prevention
- Restrict exported fields to Dagger-supported types (primitives, lists, objects, IDs).
- Keep non-schema fields unexported or tagged `json:"-"`.
- Expose complex library types via accessor methods, not fields.
When it happens
Trigger: An exported field on a Dagger object struct whose type cannot be mapped to a Dagger type: e.g. `chan int`, `func`, raw generics like `Set[T]`, a type from another module's package that isn't a valid reference, or an unsupported pointer/alias chain.
Common situations: Adding convenience fields like sync.Mutex-style handles or context-like values to an object struct; referencing types from dependency modules not exposed in the right package; upgrading Dagger so a previously-tolerated type is rejected.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to convert field type: %w
- unknown type %q
- enum types must be named
- failed to find decl for object %s: %w
- failed to find decl for named type %s: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/4408f822ae93b5b6.
Report an issue: GitHub.