dagger/dagger · error
failed to find decl for object %s: %w
Error message
failed to find decl for object %s: %w
What it means
After collecting the typed constants that make up a Go enum, parseGoEnum calls astSpecForObj to find the AST declaration for each constant so docs/pragmas/source maps can be extracted. If the AST node for the constant cannot be located, codegen fails with `failed to find decl for object %s`. This means the type-checked object and the parsed AST files are inconsistent.
Source
Thrown at cmd/codegen/generator/go/templates/module_enums.go:140
continue
}
name := obj.Name()
value := ""
if objConst.Val().Kind() == constant.String {
value = constant.StringVal(objConst.Val())
} else {
value = objConst.Val().ExactString()
}
valueSpec := &parsedEnumMember{
originalName: name,
name: name,
value: value,
}
astSpec, err := ps.astSpecForObj(objConst)
if err != nil {
return nil, fmt.Errorf("failed to find decl for object %s: %w", spec.name, err)
}
pragmas := make(map[string]any)
comment := ""
if doc := docForAstSpec(astSpec); doc != nil {
docPragmas, docComment := parsePragmaComment(doc.Text())
comment = strings.TrimSpace(docComment)
maps.Copy(pragmas, docPragmas)
}
if val, ok := astSpec.(*ast.ValueSpec); ok && val.Comment != nil {
linePragmas, lineComment := parsePragmaComment(val.Comment.Text())
if comment == "" {
comment = strings.TrimSpace(lineComment)
}
maps.Copy(pragmas, linePragmas)
}
if raw, ok := pragmas["deprecated"]; ok {View on GitHub (pinned to 82ba2681db)
Solutions
- Move the enum constants into a file that is part of the module package and not excluded by ignore patterns (e.g. not under a dagger-ignored directory, not generated dagger.gen.go).
- Verify the constants are in the same Go package that codegen parses; move them out of test files or other packages.
- Clear stale state (`dagger mod codegen regenerate`, remove .dagger build artifacts) and re-run `dagger develop`.
- Check the wrapped error (`%w`) printed after this message for the underlying reason (e.g. position lookup failure) and fix accordingly.
Example fix
// before: enum consts live in an ignored file (e.g. under an ignored dir) // ignored/consts.go const FlavorSweet Flavor = "sweet" // after: move them into the module package alongside the type // flavor.go type Flavor string const FlavorSweet Flavor = "sweet"
Defensive patterns
Strategy: validation
Validate before calling
// ensure enum constants live in parseable module package files // before codegen, confirm the constant has a position in a loaded file: // grep -rn "FlavorSweet" . --include='*.go' # must be in the module package, not an ignored dir // check ignore rules: cat .daggerignore 2>/dev/null || echo "no .daggerignore"
Prevention
- Keep enum type + constants together in a regular file of the module package
- Never place module-declared types in directories matched by dagger ignore patterns
- Read the wrapped `%w` cause in the error message to pinpoint the lookup failure
- Regenerate code after moving files between packages
When it happens
Trigger: An enum constant (`const FlavorSweet Flavor = "sweet"`) exists in type-checked package info but its declaration cannot be matched in the loaded AST — e.g. the file defining the constant was excluded from the AST load (codegen ignore patterns) or stale package state.
Common situations: The constant is defined in a file ignored by codegen (dagger ignore settings, dagger.gen.go exclusions) while the type is still referenced; mismatched package loading after moving files between packages; stale module cache after refactoring.
Related errors
- failed to find decl for named type %s: %w
- enum types must be named
- failed to find decl for named type %s: %w
- expected type spec, got %T
- failed to generate enum code for %s: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/072c4f5d52d82bce.
Report an issue: GitHub.