x/tools/go/packages: "could not determine GOARCH and Go compiler" error text is not sufficient to explain what what went wrong #30355
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
This happens when using Go 1.11 only. Go 1.12 or newer is not affected.
If the user writes the following Go program that uses
packages.Load
, and setsConfig.Dir
to a directory that doesn't contain a module:Then when running said program in module mode by setting
GO111MODULE=on
, they get an error that is not very helpful at figuring out what went wrong:This isn't sufficient information for the user to find out why that error was returned, other than to look into the source code of
packages
and debug it themselves.If
Config.Mode
is left at its defaultLoadFiles
value, the error is better at hinting what went wrong:Cause
In Go 1.12, it's possible to run
GO111MODULE=on go list unsafe
in any directory successfully. In Go 1.11, running it outside of a module gives the following error:One of the actions
packages.Load
performs is invoking thego list -f "{{context.GOARCH}} {{context.Compiler}}" -- unsafe
command in order to determine the current GOARCH and Go compiler name. If it fails, it returns an error that makes sense in the local context:https://github.com/golang/tools/blob/83362c3779f5f48611068d488a03ea7bbaddc81e/go/internal/packagesdriver/sizes.go#L90
But not when it's returned to the caller of
packages.Load
.Perhaps it can be augmented to provide more details, such as:
Given that this affects only Go 1.11 and not newer, and happens only when the Dir is incorrectly specified, the value of fixing this is not very high.
/cc @julieqiu @matloob
The text was updated successfully, but these errors were encountered: