Skip to content

Commit 998668a

Browse files
authored
Merge pull request #351 from 11xor6/fix-panic-on-import-loop
🐛 controller-gen panics when encountering an import loop
2 parents 1c750f1 + e56c6bc commit 998668a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pkg/loader/loader.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ func (l *loader) typeCheck(pkg *Package) {
243243

244244
// The imports map is keyed by import path.
245245
importedPkg := pkg.Imports()[path]
246+
if importedPkg == nil {
247+
return nil, fmt.Errorf("package %q possibly creates an import loop", path)
248+
}
246249

247250
// it's possible to have a call to check in parallel to a call to this
248251
// if one package in the package graph gets its dependency filtered out,
@@ -255,10 +258,6 @@ func (l *loader) typeCheck(pkg *Package) {
255258
importedPkg.Lock()
256259
defer importedPkg.Unlock()
257260

258-
if importedPkg == nil {
259-
return nil, fmt.Errorf("no package information for %q", path)
260-
}
261-
262261
if importedPkg.Types != nil && importedPkg.Types.Complete() {
263262
return importedPkg.Types, nil
264263
}

0 commit comments

Comments
 (0)