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 starts the Package.Error.Err field with a newline #36762

Open
perillo opened this issue Jan 25, 2020 · 5 comments
Open

cmd/go: go list starts the Package.Error.Err field with a newline #36762

perillo opened this issue Jan 25, 2020 · 5 comments
Labels
Milestone

Comments

@perillo
Copy link

@perillo perillo commented Jan 25, 2020

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

$ go version
go version go1.13.6 linux/amd64

Does this issue reproduce with the latest release?

Yes. I can reproduce it with go1.14beta1

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="github.com/perillo"
GONOSUMDB="github.com/perillo"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE="github.com/perillo"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/code/git/github.com/golang/go/src/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build700153789=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.13.6 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.13.6
uname -sr: Linux 5.4.13-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.30.
gdb --version: GNU gdb (GDB) 8.3.1

What did you do?

go1.14beta1 list -e -json /tmp/empty.go

Where empty.go is an empty file.

What did you expect to see?

{
	"Dir": "/tmp",
	"ImportPath": "command-line-arguments",
	"Match": [
		"/tmp/empty.go"
	],
	"Incomplete": true,
	"Error": {
		"ImportStack": [
			"main"
		],
		"Pos": "",
		"Err": "/tmp/empty.go:1:1: expected 'package', found 'EOF'"
	}
}

What did you see instead?

{
	"Dir": "/tmp",
	"ImportPath": "command-line-arguments",
	"Match": [
		"/tmp/empty.go"
	],
	"Incomplete": true,
	"Error": {
		"ImportStack": [
			"main"
		],
		"Pos": "",
		"Err": "\n/tmp/empty.go:1:1: expected 'package', found 'EOF'"
	}
}

There is a '\n' at the begin of the Err string.

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Jan 25, 2020

This appears to be on purpose:

// Prepare error with \n before each message.
// When printed in something like context: %v
// this will put the leading file positions each on
// its own line. It will also show all the errors
// instead of just the first, as err.Error does.
var buf bytes.Buffer
for _, e := range err {
e.Pos.Filename = ShortPath(e.Pos.Filename)
buf.WriteString("\n")
buf.WriteString(e.Error())
}
return errors.New(buf.String())

I'm not sure if I agree with the logic applying to go list -e -json, though. The error is just a string field, so it doesn't make sense for it to start with a newline - especially when there's only one error.

/cc @bcmills @jayconrod @matloob

@matloob

This comment has been minimized.

Copy link
Contributor

@matloob matloob commented Jan 27, 2020

Just for my curiousity, is this breaking something or is it purely an aesthetic concern?

@perillo

This comment has been minimized.

Copy link
Author

@perillo perillo commented Jan 27, 2020

It is just a non expected behavior.

If i'm implementing a wrapper around go list -e -find -json, probably I would not think of trimming the error string.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Jan 27, 2020

Related to #36087. Another problem for tools wrapping go list -e -json is that the error position is not reported correctly.

CL 210938 (work in progress) would fix this for the common case where there's only one scan error.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jan 29, 2020

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

@cagedmantis cagedmantis added this to the Backlog milestone Feb 3, 2020
@cagedmantis cagedmantis added the NeedsFix label Feb 3, 2020
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
6 participants
You can’t perform that action at this time.