Skip to content

Commit d5f7501

Browse files
committed
fix invalid error message "no go files to analyze"
In case of timeouts of go/packages loading we could return such error. Relates: #825
1 parent cd34a1e commit d5f7501

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/lint/load.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ func (cl *ContextLoader) loadPackages(ctx context.Context, loadMode packages.Loa
199199
cl.debugf("Built loader args are %s", args)
200200
pkgs, err := packages.Load(conf, args...)
201201
if err != nil {
202-
return nil, errors.Wrap(err, "failed to load program with go/packages")
202+
return nil, errors.Wrap(err, "failed to load with go/packages")
203+
}
204+
205+
// Currently, go/packages doesn't guarantee that error will be returned
206+
// if context was canceled. See
207+
// https://github.com/golang/tools/commit/c5cec6710e927457c3c29d6c156415e8539a5111#r39261855
208+
if ctx.Err() != nil {
209+
return nil, errors.Wrap(ctx.Err(), "timed out to load packages")
203210
}
204211

205212
if loadMode&packages.NeedSyntax == 0 {
@@ -280,7 +287,7 @@ func (cl *ContextLoader) Load(ctx context.Context, linters []*linter.Config) (*l
280287
loadMode := cl.findLoadMode(linters)
281288
pkgs, err := cl.loadPackages(ctx, loadMode)
282289
if err != nil {
283-
return nil, err
290+
return nil, errors.Wrap(err, "failed to load packages")
284291
}
285292

286293
deduplicatedPkgs := cl.filterDuplicatePackages(pkgs)

0 commit comments

Comments
 (0)