dagger/dagger · error

failed to generate underlying impl type code: %w

Error message

failed to generate underlying impl type code: %w

What it means

Emitted by the Dagger Go SDK code generator while building the body for a method that returns a slice of objects/interfaces. After the signature type code succeeds, `concreteMethodImplTypeCode` must render the concrete implementation struct type (e.g. &dagger.Directory{...}) for each slice element; failure there is wrapped as "failed to generate underlying impl type code: %w". It indicates the generator cannot produce the impl struct for the underlying element type.

Source

Thrown at cmd/codegen/generator/go/templates/module_interfaces.go:614

						})
					}
					return results, nil
			*/

			s.Id("q").Op("=").Id("q").Dot("Select").Call(Lit("id")).Line()
			s.Var().Id("idResults").Index().Struct(Id("Id").Id("dagger.ID")).Line()
			s.Id("q").Op("=").Id("q").Dot("Bind").Call(Op("&").Id("idResults")).Line()

			s.Id("err").Op(":=").Id("q").Dot("Execute").Call(Id("ctx")).Line()
			s.If(Id("err").Op("!=").Nil()).Block(Return(Nil(), Id("err"))).Line()

			underlyingReturnTypeCode, err := spec.concreteMethodSigTypeCode(returnType.underlying)
			if err != nil {
				return nil, fmt.Errorf("failed to generate underlying return type code: %w", err)
			}
			underlyingImplTypeCode, err := spec.concreteMethodImplTypeCode(returnType.underlying)
			if err != nil {
				return nil, fmt.Errorf("failed to generate underlying impl type code: %w", err)
			}
			s.Var().Id("results").Index().Add(underlyingReturnTypeCode).Line()
			s.For(List(Id("_"), Id("idResult")).Op(":=").Range().Id("idResults")).BlockFunc(func(g *Group) {
				g.Id("id").Op(":=").Id("idResult").Dot("Id")
				query := Id("r").Dot("query").Dot("Root").Call().Dot("Select").Call(Lit("node")).Dot("Arg").Call(Lit("id"), Id("id")).Dot("InlineFragment").Call(Lit(gqlSchemaName(underlyingReturnType.Name(), underlyingReturnType.ModuleName())))
				g.Id("results").Op("=").Append(Id("results"), Params(Op("&").Add(underlyingImplTypeCode).Values()).Dot("WithGraphQLQuery").Call(query))
			}).Line()

			s.Return(Id("results"), Nil())

		case *parsedPrimitiveType, nil:
			/*
				Need to return the slice of the primitive, e.g.:

					var response []string
					q = q.Bind(&response)
					return response, q.Execute(ctx)
			*/

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Inspect the wrapped inner error to identify the failing element type.
  2. Regenerate the SDK with an up-to-date dagger CLI (`dagger develop`) to refresh templates and type specs.
  3. Ensure the module providing the element type is a dependency and is itself generated/current.
  4. Fall back to returning element IDs ([]DirectoryID) if the object type cannot be supported.

Example fix

// before
func (m *Mod) All(ctx context.Context) ([]MissingType, error)
// after: re-add the dependency module or use IDs
func (m *Mod) All(ctx context.Context) ([]DirectoryID, error)
Defensive patterns

Strategy: validation

Validate before calling

// check the dependency module defining the element type exists and is current
if _, err := os.Stat("dagger.json"); err == nil {
    var cfg map[string]any
    json.NewDecoder(mustOpen("dagger.json")).Decode(&cfg)
    for dep := range cfg["dependencies"].(map[string]any) {
        if _, err := os.Stat(filepath.Join(dep, "dagger.json")); err != nil {
            log.Fatalf("dependency module %s missing; run `dagger develop` in it first", dep)
        }
    }
}

Type guard

func hasImplType(t ParsedType) bool {
    if named, ok := t.(NamedParsedType); ok {
        return named.Name() != "" // impl structs are generated only for named types
    }
    return false
}

Try / catch

underlyingImplTypeCode, err := spec.concreteMethodImplTypeCode(returnType.underlying)
if err != nil {
    return nil, fmt.Errorf("failed to generate underlying impl type code for %s: %w", returnType.underlying.Name(), err)
}

Prevention

When it happens

Trigger: Codegen over a module function returning []Iface/[]Object where the element type's implementation struct cannot be generated — e.g. the named type references a module or object not present in the current introspection input.

Common situations: Cross-module types whose defining module wasn't codegen'd; renames of objects between core/SDK versions; stale generated code referencing removed types.

Related errors


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