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

  1. Read the wrapped inner error to see which field/type was rejected.
  2. Change the field to a supported Dagger type (primitive, string-enum, list, another Dagger object, or ID scalar).
  3. Make unsupported fields unexported (lowercase) so they are skipped by codegen.
  4. Use a `json:"-"` tag to exclude an exported field from the schema.
  5. 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

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

Related errors


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