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: 'go list -e' doesn't print scanner error position in .Error.Pos #36087

Open
jayconrod opened this issue Dec 11, 2019 · 2 comments
Open

cmd/go: 'go list -e' doesn't print scanner error position in .Error.Pos #36087

jayconrod opened this issue Dec 11, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Dec 11, 2019

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

$ go version
go version devel +7d24e9581a Mon Dec 9 20:19:32 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/jayconrod/Code/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jayconrod/Code/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jayconrod/Code/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build939442357=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go list -e -f '{{.Error.Pos}} => {{.Error.Err}}' .
stdout 'p.go:1:9 => illegal character'

-- go.mod --
module example.com/first

go 1.12
-- p.go --
package ?

What did you expect to see?

The .Error.Pos field should be populated with the position where the error occurred, in this case, the location of the illegal character.

A potential problem here is that there may be multiple errors, and there isn't a reasonable way to report all of them with positions, given the current structure of the JSON output. We should at least report the position for the first error.

What did you see instead?

The position is printed in the error message instead of the .Error.Pos field.

 => 
p.go:1:9: illegal character U+003F '?'

This also confuses golang.org/x/tools/go/packages and tools like gopls based on it.

@jayconrod jayconrod added the NeedsFix label Dec 11, 2019
@jayconrod jayconrod added this to the Backlog milestone Dec 11, 2019
@jayconrod jayconrod self-assigned this Dec 11, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 11, 2019

Change https://golang.org/cl/210938 mentions this issue: cmd/go: report scan error position in 'go list -e'

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 13, 2019

Change https://golang.org/cl/211337 mentions this issue: cmd/fiximports: fix 'go list' error formatting

gopherbot pushed a commit to golang/tools that referenced this issue Dec 17, 2019
Error positions should be printed, when specified.

Also, made main_test less picky about whitespace before and after
error output.

After this change, the test for cmd/fiximports should pass before and
after CL 210938.

Updates golang/go#36087

Change-Id: I681d1ee07f7f19a0d9716b88678e2737f4c691de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211337
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.