Skip to content

When using go1.24 or later, the Go: Test command no longer displays compile errors #3744

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

Open
shibayu36 opened this issue Apr 3, 2025 · 6 comments
Labels
Go Companion Issues relating to the Go Companion extension
Milestone

Comments

@shibayu36
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.24.1 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.18.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.98.2 ddc367ed5c8936efe395cffeec279b04ffd7db78 arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.46.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/shibayu36/go
GOROOT: /opt/homebrew/Cellar/go/1.24.1/libexec
PATH: /opt/homebrew/Cellar/go/1.24.1/libexec/bin:/Users/shibayu36/.codeium/windsurf/bin:/Users/shibayu36/.poetry/bin:/opt/homebrew/Cellar/zplug/2.4.2/bin:/opt/homebrew/opt/zplug/bin:/opt/homebrew/opt/gettext/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/imagemagick@6/bin:/usr/local/opt/texinfo/bin:/opt/homebrew/opt/openssl@3/bin:/usr/local/heroku/bin:/Users/shibayu36/go/bin:/Users/shibayu36/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/shibayu36/.local/bin:/Users/shibayu36/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/sbin:/bin:/sbin:/Users/shibayu36/.tfenv/bin:/usr/local/opt/scala/bin:/Users/shibayu36/.poetry/bin:/Users/shibayu36/dotnet:/Users/shibayu36/.orbstack/bin:/opt/homebrew/opt/fzf/bin:/Users/shibayu36/.cache/lm-studio/bin
PATH (vscode launched with): /Users/shibayu36/.codeium/windsurf/bin:/Users/shibayu36/.poetry/bin:/opt/homebrew/Cellar/zplug/2.4.2/bin:/opt/homebrew/opt/zplug/bin:/opt/homebrew/opt/gettext/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/imagemagick@6/bin:/usr/local/opt/texinfo/bin:/opt/homebrew/opt/openssl@3/bin:/usr/local/heroku/bin:/Users/shibayu36/go/bin:/Users/shibayu36/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/shibayu36/.local/bin:/Users/shibayu36/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/sbin:/bin:/sbin:/Users/shibayu36/.tfenv/bin:/usr/local/opt/scala/bin:/Users/shibayu36/.poetry/bin:/Users/shibayu36/dotnet:/Users/shibayu36/.orbstack/bin:/opt/homebrew/opt/fzf/bin:/Users/shibayu36/.cache/lm-studio/bin

## Tools

	go:	/opt/homebrew/bin/go: go version go1.24.1 darwin/arm64

	gopls:	/Users/shibayu36/go/bin/gopls	(version: v0.18.1 built with go: go1.24.0)
	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/Users/shibayu36/go/bin/dlv	(version: v1.24.0 built with go: go1.24.0)
	golangci-lint:	/Users/shibayu36/go/bin/golangci-lint	(version: v1.64.6 built with go: go1.24.0)

## Go env

Workspace Folder (vscode-go): /Users/shibayu36/development/src/github.com/golang/vscode-go

	AR='ar'
	CC='cc'
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_ENABLED='1'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	CXX='c++'
	GCCGO='gccgo'
	GO111MODULE=''
	GOARCH='arm64'
	GOARM64='v8.0'
	GOAUTH='netrc'
	GOBIN=''
	GOCACHE='/Users/shibayu36/Library/Caches/go-build'
	GOCACHEPROG=''
	GODEBUG=''
	GOENV='/Users/shibayu36/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFIPS140='off'
	GOFLAGS=''
	GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/7r/7nyxrx15693bsgd6gwv749g00000gn/T/go-build2791924945=/tmp/go-build -gno-record-gcc-switches -fno-common'
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMOD='/Users/shibayu36/development/src/github.com/golang/vscode-go/go.mod'
	GOMODCACHE='/Users/shibayu36/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='darwin'
	GOPATH='/Users/shibayu36/go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
	GOSUMDB='sum.golang.org'
	GOTELEMETRY='local'
	GOTELEMETRYDIR='/Users/shibayu36/Library/Application Support/go/telemetry'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.24.1'
	GOWORK=''
	PKG_CONFIG='pkg-config'

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

  "go.alternateTools": {
    "go": "/opt/homebrew/bin/go",
    "go-langserver": "gopls"
  },
  "go.languageServerExperimentalFeatures": {
    "autoComplete": true,
    "format": true
  },
  "go.lintFlags": [
    "--fast"
  ],
  "go.lintTool": "golangci-lint",
  "go.testFlags": [
    "-v",
    "-count=1",
    "-timeout=120s"
  ],
  "go.toolsManagement.autoUpdate": true,
  "[go]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": "explicit"
    },
    "editor.formatOnSave": true,
    "editor.snippetSuggestions": "none"
  },

Describe the bug

After upgrading to Go 1.24, running the Go: Test command (e.g. Go: Test File) no longer displays compile errors in the Output.

It is probably because in go1.24, go test -json now returns the build output in JSON as well.

https://tip.golang.org/doc/go1.24

Furthermore, go test -json now reports build output and failures in JSON, interleaved with test result JSON. These are distinguished by new Action types, but if they cause problems in a test integration system, you can revert to the text build output with GODEBUG setting gotestjsonbuildtext=1.

Steps to reproduce the behavior:

  1. Edit a file to cause a compilation error.
  2. Run the Go: Test File command.
  3. Check the output.

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Cause a compile error
Image

When running Go: Test File using go1.24
Image

When running Go: Test File using go1.23

Image

@gopherbot gopherbot added this to the Untriaged milestone Apr 3, 2025
@firelizzard18 firelizzard18 added the Go Companion Issues relating to the Go Companion extension label Apr 3, 2025
@findleyr
Copy link
Member

findleyr commented Apr 4, 2025

CC @h9jiang

I'm confused, as I get build errors on stderr both 1.23 and 1.24, so I'm not sure why the Go version would matter here.

@firelizzard18
Copy link
Contributor

@findleyr Go 1.24 changes how go test -json behaves. Given:

func Test(t *testing.T) { 1 }

go1.23.1 test -json writes build errors to stderr, unformatted:

# test [test.test]
./test_test.go:5:27: 1 (untyped int constant) is not used
{"Time":"2025-04-04T12:08:57.467679875-05:00","Action":"start","Package":"test"}
{"Time":"2025-04-04T12:08:57.467719442-05:00","Action":"output","Package":"test","Output":"FAIL\ttest [build failed]\n"}
{"Time":"2025-04-04T12:08:57.467723667-05:00","Action":"fail","Package":"test","Elapsed":0}

go1.24.2 test -json JSON-ifies build errors and writes them to stdout, the same as regular error output:

{"ImportPath":"test [test.test]","Action":"build-output","Output":"# test [test.test]\n"}
{"ImportPath":"test [test.test]","Action":"build-output","Output":"./test_test.go:5:27: 1 (untyped int constant) is not used\n"}
{"ImportPath":"test [test.test]","Action":"build-fail"}
{"Time":"2025-04-04T12:14:45.320982183-05:00","Action":"start","Package":"test"}
{"Time":"2025-04-04T12:14:45.32101052-05:00","Action":"output","Package":"test","Output":"FAIL\ttest [build failed]\n"}
{"Time":"2025-04-04T12:14:45.321015248-05:00","Action":"fail","Package":"test","Elapsed":0,"FailedBuild":"test [test.test]"}

Presumably, the existing code is detecting output that's written to stderr (and probably the return code) and using that to detect and display failures. And now, the build error output has been merged into the JSON event stream with new Action values (build-output, build-fail) that aren't handled.

@findleyr
Copy link
Member

findleyr commented Apr 4, 2025

Thanks @firelizzard18 and @shibayu36 for investigating.

@h9jiang this is a semi-urgent bug to fix. Putting in the next milestone. It should hopefully be easy to address.

@findleyr findleyr modified the milestones: Untriaged, v0.48.0 Apr 4, 2025
@firelizzard18
Copy link
Contributor

I believe the relevant code is in extension/src/testUtils.ts, goTest or one of the functions it calls. Though now that I look at it I'm confused. The test explorer (old or new) always uses -json but it appears that @shibayu36 is using the legacy test support and I can reproduce this issue with the legacy code lenses. And I thought that would run the test without -json and would use processTestResultLineInStandardMode to handle output, which shouldn't have this issue. But maybe it's still adding -json somewhere. If that's the case, then updating processTestResultLineInJSONMode may be sufficient:

- 			if (m.Action !== 'output' || !m.Output) {
+ 			if (!(m.Action === 'output' || m.Action === 'build-output') || !m.Output) {
 				return;
 			}

@shibayu36
Copy link
Author

shibayu36 commented Apr 7, 2025

I think the -json flag is being added because I have -v in go.testFlags.

"go.testFlags": [
  "-v",
  "-count=1",
  "-timeout=120s"
]

As a result, the -json output might be enabled by const addJSONFlag = (userFlags.includes('-v') || testconfig.goTestOutputConsumer) && !userFlags.includes('-json');

and that could be why outBuf.onLine((line) => processTestResultLine(line)); can't handle the output properly.

By the way, when I removed -v from the settings, the compile errors started showing up again.

@firelizzard18
Copy link
Contributor

That does seem like the answer and I think I also have -v set. Thanks for pointing that out, I missed it when I looked at that code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go Companion Issues relating to the Go Companion extension
Projects
Status: Todo
Development

No branches or pull requests

4 participants