Skip to content

Commit 926907e

Browse files
committed
check ld.Context directly and return if canceled
1 parent 40493ac commit 926907e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

go/packages/packages.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,18 +647,15 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
647647
}
648648
wg.Wait()
649649
}
650-
650+
// check is context still valid
651+
if ld.Context.Err() != nil {
652+
return nil, ld.Context.Err()
653+
}
651654
result := make([]*Package, len(initial))
652655
for i, lpkg := range initial {
653656
result[i] = lpkg.Package
654657
}
655658
for i := range ld.pkgs {
656-
// return err on loading canceled by context
657-
numErrs := len(ld.pkgs[i].Errors)
658-
if numErrs > 0 &&
659-
ld.pkgs[i].Errors[numErrs-1].Kind == ContextCancelError {
660-
return nil, context.Canceled
661-
}
662659
// Clear all unrequested fields, for extra de-Hyrum-ization.
663660
if ld.requestedMode&NeedName == 0 {
664661
ld.pkgs[i].Name = ""

0 commit comments

Comments
 (0)