Skip to content

cmd/go: poor error message for misseting GOENV on windows #73695

@SkybuckFlying

Description

@SkybuckFlying

Go version

go version go1.19.13 windows/amd64

Output of go env in your module/workspace:

PS G:\GOFOLDERS\version 1.19> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=G:\GOFOLDERS\version 1.19\GOBIN
set GOCACHE=G:\GOFOLDERS\version 1.19\GOCACHE
set GOENV=G:\GOFOLDERS\version 1.19\GOENV
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=G:\GOFOLDERS\version 1.19\GOPATH\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=G:\GOFOLDERS\version 1.19\GOPATH
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=G:\GOFOLDERS\version 1.19\GOROOT
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=G:\GOFOLDERS\version 1.19\GOROOT\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.13
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=G:\Temp\go-build758810112=/tmp/go-build -gno-record-gcc-switches
PS G:\GOFOLDERS\version 1.19>

What did you do?

I want GO to use G: drive excluslively and not wear and tear my C: SSD drive:

For this purpose a batch file was created to make sense out of the mess that GO and it's installers create:
(the installers cannot be used to install multiple go versions because they de-install the old versions, so the installers were by-passed and instead zip files used and extract to GOROOT).

SetupGOVersion1.19V2.bat

@echo off
echo Setting up Go environment for version 1.19...

:: Define base folder
SET GO_VERSION=version 1.19
SET BASE_PATH=G:\GOFOLDERS\%GO_VERSION%

:: Create necessary folders
mkdir "%BASE_PATH%\GOPATH"
mkdir "%BASE_PATH%\GOCACHE"
mkdir "%BASE_PATH%\GOMODCACHE"
mkdir "%BASE_PATH%\GOROOT"
mkdir "%BASE_PATH%\GOBIN"
mkdir "%BASE_PATH%\GOENV"

:: Configure Go environment variables
go env -w GOPATH="G:\GOFOLDERS\version 1.19\GOPATH"
go env -w GOCACHE="G:\GOFOLDERS\version 1.19\GOCACHE"
go env -w GOMODCACHE="G:\GOFOLDERS\version 1.19\GOMODCACHE"
go env -w GOROOT="G:\GOFOLDERS\version 1.19\GOROOT"
go env -w GOBIN="G:\GOFOLDERS\version 1.19\GOBIN"
go env -w GOENV="G:\GOFOLDERS\version 1.19\GOENV"

echo Setup complete! Restart your shell to apply changes.
pause

I also want the capability to try out different GO versions, I want to use GopherJS and try it out then I want to convert it to GopherDelphi so I can convert ViteLabs blockchain from Go to Delphi and say goodbye to the mess/dictactorship that GO is which is annoying. I just want access to all source code files and set things up the way I want without all this automation nonsense which seems to backfire and create a mess out of things, though I will continue to try and make sense out of all these paths that GO seems to want to use, vendor not yet included, packages, modules, bin paths, gopaths, caches, it's a total and completely understandable mess.

Delphi on the other hand has two things mainly: A runtime environment and my source files/libraries which I can set up nicely in a project file, this is the way to do something developement, not this automatic crap that nobody understands.

Anyway continueing with the problem:

Environment variables setup in windows 11/advanced settings as follows:
GOROOT
GOBIN
GOPATH
GOCACHE
GOENV

To these folders

Also GOROOT\BIN and GOBIN added to path.

Go executes commands.

However:

go env -w GOFLAGS="-mod=vendor"

returns error:

PS G:\GOFOLDERS\version 1.19> go env -w GOFLAGS="-mod=vendor"
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
PS G:\GOFOLDERS\version 1.19>

The env file was first copied from some messy windows 11 user app data folder to this folder above.

G:\GOFOLDERS\version 1.19\GOENV

The contents of the file is:

GOBIN=G:\GOFOLDERS\version 1.19\GOBIN
GOCACHE=G:\GOFOLDERS\version 1.19\GOCACHE
GOFLAGS=-mod=vendor
GOMODCACHE=G:\GOFOLDERS\version 1.19\GOMODCACHE
GOPATH=G:\GOFOLDERS\version 1.19\GOPATH
GOROOT=G:\GOFOLDERS\version 1.19\GOROOT

There was a copieing error initially, some file was still open in editor or command line, file was re-created, permissions given, full control via command:

icacls "G:\GOFOLDERS\version 1.19\GOENV" /grant Everyone:F /T

Still the error remains...

Very weird...

I suspect it might be a bug in this go version... otherwise I am stumped.

Also the cache folder was not set by the command env -v etc... that was odd, so added this environment variable as well.

Final remark:

Please test your GO software to run of a different drive then C:

Use resource monitor on from task manager/performance on windows 11 to make absolutely sure that not a single file is written to C:

That would be a blessing.

What did you see happen?

PS G:\GOFOLDERS\version 1.19> go env -w GOFLAGS="-mod=vendor"
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
PS G:\GOFOLDERS\version 1.19>

What did you expect to see?

It should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionIssues that are questions about using Go.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions