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

cmd/go: poor error message for nonmatching go-import tags #41547

Open
robpike opened this issue Sep 22, 2020 · 4 comments
Open

cmd/go: poor error message for nonmatching go-import tags #41547

robpike opened this issue Sep 22, 2020 · 4 comments
Milestone

Comments

@robpike
Copy link
Contributor

@robpike robpike commented Sep 22, 2020

What version of Go are you using (go version)?

$ go version
go version devel +1e6ad65b43 Tue Sep 8 18:52:38 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Catalina, MacOS, amd64.

What did you do?

I typed by mistake the wrong import string; I forgot the cmd, and got 1472 characters of this:

% go get robpike.io/tab
package robpike.io/tab: unrecognized import path "robpike.io/tab": parse https://robpike.io/tab?go-get=1: no go-import meta tags (meta tag robpike.io/cmd/doc did not match import path robpike.io/tab, meta tag robpike.io/ivy did not match import path robpike.io/tab, meta tag robpike.io/cmd/freq did not match import path robpike.io/tab, meta tag robpike.io/cmd/hira did not match import path robpike.io/tab, meta tag robpike.io/cmd/kana did not match import path robpike.io/tab, meta tag robpike.io/cmd/kata did not match import path robpike.io/tab, meta tag robpike.io/cmd/now did not match import path robpike.io/tab, meta tag robpike.io/cmd/strings did not match import path robpike.io/tab, meta tag robpike.io/cmd/translate did not match import path robpike.io/tab, meta tag robpike.io/cmd/typo did not match import path robpike.io/tab, meta tag robpike.io/cmd/unicode did not match import path robpike.io/tab, meta tag robpike.io/filter did not match import path robpike.io/tab, meta tag robpike.io/toy did not match import path robpike.io/tab, meta tag robpike.io/nihongo did not match import path robpike.io/tab, meta tag robpike.io/cmd/scrub did not match import path robpike.io/tab, meta tag robpike.io/cmd/tab did not match import path robpike.io/tab, meta tag robpike.io/cmd/sid did not match import path robpike.io/tab, meta tag robpike.io/cmd/script did not match import path robpike.io/tab, meta tag robpike.io/lisp did not match import path robpike.io/tab)
% go get robpike.io/cmd/tab
%

Reflowed using fmt, that's:

package robpike.io/tab: unrecognized import path "robpike.io/tab":
parse https://robpike.io/tab?go-get=1: no go-import meta tags (meta
tag robpike.io/cmd/doc did not match import path robpike.io/tab,
meta tag robpike.io/ivy did not match import path robpike.io/tab,
meta tag robpike.io/cmd/freq did not match import path robpike.io/tab,
meta tag robpike.io/cmd/hira did not match import path robpike.io/tab,
meta tag robpike.io/cmd/kana did not match import path robpike.io/tab,
meta tag robpike.io/cmd/kata did not match import path robpike.io/tab,
meta tag robpike.io/cmd/now did not match import path robpike.io/tab,
meta tag robpike.io/cmd/strings did not match import path robpike.io/tab,
meta tag robpike.io/cmd/translate did not match import path
robpike.io/tab, meta tag robpike.io/cmd/typo did not match import
path robpike.io/tab, meta tag robpike.io/cmd/unicode did not match
import path robpike.io/tab, meta tag robpike.io/filter did not match
import path robpike.io/tab, meta tag robpike.io/toy did not match
import path robpike.io/tab, meta tag robpike.io/nihongo did not
match import path robpike.io/tab, meta tag robpike.io/cmd/scrub did
not match import path robpike.io/tab, meta tag robpike.io/cmd/tab
did not match import path robpike.io/tab, meta tag robpike.io/cmd/sid
did not match import path robpike.io/tab, meta tag robpike.io/cmd/script
did not match import path robpike.io/tab, meta tag robpike.io/lisp
did not match import path robpike.io/tab)

What did you expect to see?

A shorter, better-formatted error message. This one doesn't even have newlines.

% go get robpike.io/tab
package robpike.io/tab: unrecognized import path "robpike.io/tab": parse https://robpike.io/tab?go-get=1: no go-import m

What did you see instead?

A long, poorly-formatted error mess.

@bcmills bcmills changed the title cmd/go: poor error message with bad vanity import cmd/go: poor error message for nonmatching go-import tags Sep 22, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Sep 22, 2020

@bcmills bcmills added this to the Backlog milestone Sep 22, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Sep 22, 2020

The error text in question comes from here:

func (m ImportMismatchError) Error() string {
formattedStrings := make([]string, len(m.mismatches))
for i, pre := range m.mismatches {
formattedStrings[i] = fmt.Sprintf("meta tag %s did not match import path %s", pre, m.importPath)
}
return strings.Join(formattedStrings, ", ")
}

(The verbose error message was added in CL 25121, released in Go 1.8.)

@bcmills
Copy link
Member

@bcmills bcmills commented Sep 22, 2020

There are some other redundancies in that error string that we should eliminate too.

(This is another instance of the over-wrapping problem described in my experience report.)

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 13, 2020

Change https://golang.org/cl/261777 mentions this issue: cmd/go/internal/vcs: improve error message for mismatching go-import tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.