vitessio/vitess · error
no scope found for type '%s'
Error message
no scope found for type '%s'
What it means
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.
Source
Thrown at go/tools/asthelpergen/asthelpergen.go:328
return nil, err
}
return it, nil
}
// findTypeObject finds the types.Object for the given interface from the given scopes.
func findTypeObject(interfaceToFind string, scopes map[string]*types.Scope) (types.Object, error) {
pos := strings.LastIndexByte(interfaceToFind, '.')
if pos < 0 {
return nil, fmt.Errorf("unexpected input type: %s", interfaceToFind)
}
pkgname := interfaceToFind[:pos]
typename := interfaceToFind[pos+1:]
scope := scopes[pkgname]
if scope == nil {
return nil, fmt.Errorf("no scope found for type '%s'", interfaceToFind)
}
tt := scope.Lookup(typename)
if tt == nil {
return nil, fmt.Errorf("no type called '%s' found in '%s'", typename, pkgname)
}
return tt, nil
}
var _ generatorSPI = (*astHelperGen)(nil)
func (gen *astHelperGen) scope() *types.Scope {
return gen._scope
}
func (gen *astHelperGen) addType(t types.Type) {
gen.todo = append(gen.todo, t)
}View on GitHub (pinned to 01a25a7d17)
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)
Example fix
// before
Packages: []string{"vitess.io/vitess/go/vt/sqlparser/ast"}
// after
Packages: []string{"vitess.io/vitess/go/vt/sqlparser"} Defensive patterns
Strategy: validation
Validate before calling
pkg := "vitess.io/vitess/go/vt/sqlparser"
for _, iface := range options.Visitable {
if strings.HasPrefix(iface, pkg+".") && !slices.Contains(options.Packages, pkg) {
return fmt.Errorf("package %s must be in Options.Packages for %s", pkg, iface)
}
} Type guard
func pkgLoaded(scopes map[string]*types.Scope, iface string) bool {
return scopes[iface[:strings.LastIndexByte(iface, '.')]] != nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Adding an interface for generation but forgetting to add its package to Options.Packages; renamed import paths after a refactor.
Related errors
- must specify exactly one package
- failed to load packages: %w
- no type called '%s' found in '%s'
- package '%s' does not contain 'ast_format.go'
- interface %s implemented by %s (%s as %T) without ptr
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/02a2e5b85bbbdd16.
Report an issue: GitHub.