{"record":{"id":"072c4f5d52d82bce","repo":"dagger/dagger","slug":"failed-to-find-decl-for-object-s-w","errorCode":null,"errorMessage":"failed to find decl for object %s: %w","messagePattern":"failed to find decl for object (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/templates/module_enums.go","lineNumber":140,"sourceCode":"\t\t\tcontinue\n\t\t}\n\n\t\tname := obj.Name()\n\t\tvalue := \"\"\n\t\tif objConst.Val().Kind() == constant.String {\n\t\t\tvalue = constant.StringVal(objConst.Val())\n\t\t} else {\n\t\t\tvalue = objConst.Val().ExactString()\n\t\t}\n\n\t\tvalueSpec := &parsedEnumMember{\n\t\t\toriginalName: name,\n\t\t\tname:         name,\n\t\t\tvalue:        value,\n\t\t}\n\t\tastSpec, err := ps.astSpecForObj(objConst)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to find decl for object %s: %w\", spec.name, err)\n\t\t}\n\n\t\tpragmas := make(map[string]any)\n\t\tcomment := \"\"\n\t\tif doc := docForAstSpec(astSpec); doc != nil {\n\t\t\tdocPragmas, docComment := parsePragmaComment(doc.Text())\n\t\t\tcomment = strings.TrimSpace(docComment)\n\t\t\tmaps.Copy(pragmas, docPragmas)\n\t\t}\n\t\tif val, ok := astSpec.(*ast.ValueSpec); ok && val.Comment != nil {\n\t\t\tlinePragmas, lineComment := parsePragmaComment(val.Comment.Text())\n\t\t\tif comment == \"\" {\n\t\t\t\tcomment = strings.TrimSpace(lineComment)\n\t\t\t}\n\t\t\tmaps.Copy(pragmas, linePragmas)\n\t\t}\n\n\t\tif raw, ok := pragmas[\"deprecated\"]; ok {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/templates/module_enums.go#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: enum consts live in an ignored file (e.g. under an ignored dir)\n// ignored/consts.go\nconst FlavorSweet Flavor = \"sweet\"\n\n// after: move them into the module package alongside the type\n// flavor.go\ntype Flavor string\n\nconst FlavorSweet Flavor = \"sweet\"","handlingStrategy":"validation","validationCode":"// ensure enum constants live in parseable module package files\n// before codegen, confirm the constant has a position in a loaded file:\n// grep -rn \"FlavorSweet\" . --include='*.go'   # must be in the module package, not an ignored dir\n// check ignore rules:\ncat .daggerignore 2>/dev/null || echo \"no .daggerignore\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["dagger","codegen","go","ast","enum"],"backgroundTag":"codegen-decl-not-found","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}