{"record":{"id":"02a2e5b85bbbdd16","repo":"vitessio/vitess","slug":"no-scope-found-for-type-s","errorCode":null,"errorMessage":"no scope found for type '%s'","messagePattern":"no scope found for type '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/asthelpergen/asthelpergen.go","lineNumber":328,"sourceCode":"\t\treturn nil, err\n\t}\n\n\treturn it, nil\n}\n\n// findTypeObject finds the types.Object for the given interface from the given scopes.\nfunc findTypeObject(interfaceToFind string, scopes map[string]*types.Scope) (types.Object, error) {\n\tpos := strings.LastIndexByte(interfaceToFind, '.')\n\tif pos < 0 {\n\t\treturn nil, fmt.Errorf(\"unexpected input type: %s\", interfaceToFind)\n\t}\n\n\tpkgname := interfaceToFind[:pos]\n\ttypename := interfaceToFind[pos+1:]\n\n\tscope := scopes[pkgname]\n\tif scope == nil {\n\t\treturn nil, fmt.Errorf(\"no scope found for type '%s'\", interfaceToFind)\n\t}\n\n\ttt := scope.Lookup(typename)\n\tif tt == nil {\n\t\treturn nil, fmt.Errorf(\"no type called '%s' found in '%s'\", typename, pkgname)\n\t}\n\treturn tt, nil\n}\n\nvar _ generatorSPI = (*astHelperGen)(nil)\n\nfunc (gen *astHelperGen) scope() *types.Scope {\n\treturn gen._scope\n}\n\nfunc (gen *astHelperGen) addType(t types.Type) {\n\tgen.todo = append(gen.todo, t)\n}","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/asthelpergen/asthelpergen.go#L310-L346","documentation":"After splitting 'pkgname.TypeName', findTypeObject looks up pkgname in the loaded scopes map. If no loaded package has an import path matching pkgname, this error is returned, meaning the package containing the interface was not loaded or the path is misspelled.","triggerScenarios":"Options lists interface 'some/pkg/SQLNode' but options.Packages does not include 'some/pkg', so scopes lacks that key; or the package path is misspelled/outdated after a module reorganization.","commonSituations":"Adding an interface for generation but forgetting to add its package to Options.Packages; renamed import paths after a refactor.","solutions":["Add the interface's package path to Options.Packages so it gets loaded into scopes","Verify the exact import path of the interface (go doc or IDE copy-reference)","Ensure findTypeObject keys and loaded package paths use identical path strings (no vendor/ prefix mismatch)"],"exampleFix":"// before\nPackages: []string{\"vitess.io/vitess/go/vt/sqlparser/ast\"}\n// after\nPackages: []string{\"vitess.io/vitess/go/vt/sqlparser\"}","handlingStrategy":"validation","validationCode":"pkg := \"vitess.io/vitess/go/vt/sqlparser\"\nfor _, iface := range options.Visitable {\n    if strings.HasPrefix(iface, pkg+\".\") && !slices.Contains(options.Packages, pkg) {\n        return fmt.Errorf(\"package %s must be in Options.Packages for %s\", pkg, iface)\n    }\n}","typeGuard":"func pkgLoaded(scopes map[string]*types.Scope, iface string) bool {\n    return scopes[iface[:strings.LastIndexByte(iface, '.')]] != nil\n}","tryCatchPattern":null,"preventionTips":["Every interface listed for generation must belong to a package in Options.Packages","Update interface paths after any module/package reorganization","Add a unit test asserting all configured interfaces resolve in scopes"],"tags":["codegen","scope-lookup","go-packages"],"backgroundTag":"package-not-loaded","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}