dagger/dagger · error
failed to parse type reference: %w
Error message
failed to parse type reference: %w
What it means
When resolving a function argument's declared Go type into a Dagger TypeDef, parseGoTypeReference encountered a type the codegen cannot represent (unsupported types like interfaces without names, funcs, chans, or unresolvable external types). The failure is wrapped as 'failed to parse type reference'.
Source
Thrown at cmd/codegen/generator/go/templates/module_funcs.go:483
deprecated = &reason
}
ignore := []string{}
if v, ok := pragmas["ignore"]; ok {
err := mapstructure.Decode(v, &ignore)
if err != nil {
return paramSpec{}, fmt.Errorf("ignore pragma %q, must be a valid JSON array: %w", v, err)
}
}
// ignore ctx arg for parsing type reference
isContext := paramType.String() == contextTypename
var typeSpec ParsedType
if !isContext {
var err error
typeSpec, err = ps.parseGoTypeReference(baseType, nil, isPtr)
if err != nil {
return paramSpec{}, fmt.Errorf("failed to parse type reference: %w", err)
}
}
name := field.Name()
if name == "" && typeSpec != nil {
// emulate struct behaviour, where a field with no name gets the type name
name = typeSpec.GoType().String()
}
var sourceMap *sourceMap
if astField != nil {
sourceMap = ps.sourceMap(astField)
}
return paramSpec{
name: name,
paramType: paramType,
sourceMap: sourceMap,View on GitHub (pinned to 82ba2681db)
Solutions
- Change the argument type to a Dagger-supported type (primitives, string, slices, maps, named structs, named interfaces, Directory/File/etc.)
- Check the wrapped %w error to identify the unsupported underlying type
- Move the type into the module package so codegen can visit and name it
Example fix
// before func (m *Mod) Foo(ctx context.Context, cb func(string) error) error // after func (m *Mod) Foo(ctx context.Context, message string) error
Defensive patterns
Strategy: type-guard
Validate before calling
// ensure argument types are Dagger-representable before codegen // allowed: string, bool, int, float, slice, map, named struct, named interface, *Directory, *File, *Container...
Type guard
func isDaggerSupportedArgType(t reflect.Type) bool {
switch t.Kind() {
case reflect.Chan, reflect.Func, reflect.UnsafePointer, reflect.Complex64, reflect.Complex128:
return false
case reflect.Interface:
return t.Name() != "" // interfaces must be named
}
return true
} Try / catch
if err := runCodegen(); err != nil {
if strings.Contains(err.Error(), "failed to parse type reference") {
// inspect the wrapped error and replace the unsupported argument type
}
} Prevention
- Avoid func/channel/interface{} function arguments
- Keep referenced types in the module package so codegen visits them
- Read the wrapped cause (%w) for the exact unsupported type
When it happens
Trigger: A Dagger function argument typed with something unsupported: an unnamed interface, func, channel, map with unsupported value types, or a type from a package not visited by codegen.
Common situations: Using callback-style func args; using types from unanalyzed dependencies; typos causing resolution to unexpected generic/alias types; SDK upgrades adding stricter checks.
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
- 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
- nested structs are not supported
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/ae31a93b28446789.
Report an issue: GitHub.