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

Closed
jayconrod opened this issue Dec 11, 2019 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jayconrod
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. label Dec 11, 2019
@jayconrod jayconrod added this to the Backlog milestone Dec 11, 2019
@jayconrod jayconrod self-assigned this Dec 11, 2019
@gopherbot
Copy link

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

@gopherbot
Copy link

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>
@gopherbot
Copy link

Change https://golang.org/cl/304069 mentions this issue: cmd/go/internal/load: use setLoadPackageDataError in loadImport

gopherbot pushed a commit that referenced this issue Mar 25, 2021
This makes the error handling in loadImport somewhat more uniform,
with no discernable effect on reported errors.

Noticed in CL 303869.

Updates #36087
Updates #38034

This somewhat simplifies the code, with no discernable effect on

Change-Id: I30521f658f264d6f99d1844d6701269bbb372246
Reviewed-on: https://go-review.googlesource.com/c/go/+/304069
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@golang golang locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants