Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid error message "no go files to analyze" #1154

Merged
merged 1 commit into from May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/lint/load.go
Expand Up @@ -199,7 +199,14 @@ func (cl *ContextLoader) loadPackages(ctx context.Context, loadMode packages.Loa
cl.debugf("Built loader args are %s", args)
pkgs, err := packages.Load(conf, args...)
if err != nil {
return nil, errors.Wrap(err, "failed to load program with go/packages")
return nil, errors.Wrap(err, "failed to load with go/packages")
}

// Currently, go/packages doesn't guarantee that error will be returned
// if context was canceled. See
// https://github.com/golang/tools/commit/c5cec6710e927457c3c29d6c156415e8539a5111#r39261855
if ctx.Err() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

if err := ctx.Err(); err != nil {

would do? It would allow to avoid calling ctx.Err() twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any profit to save nanoseconds here :)

Copy link
Member Author

@jirfag jirfag May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: maybe microseconds

func (c *cancelCtx) Err() error {
	c.mu.Lock()
	err := c.err
	c.mu.Unlock()
	return err
}

It doesn't make sense to waste time on such micro-optimization, there are a lot of things to save seconds of time

return nil, errors.Wrap(ctx.Err(), "timed out to load packages")
}

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

deduplicatedPkgs := cl.filterDuplicatePackages(pkgs)
Expand Down