Skip to content

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

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

Closed
SkybuckFlying opened this issue May 13, 2025 · 23 comments
Closed

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

SkybuckFlying opened this issue May 13, 2025 · 23 comments
Labels
Question Issues that are questions about using Go.

Comments

@SkybuckFlying
Copy link

SkybuckFlying commented May 13, 2025

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.

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

I shall now try to install a newer version of GO the same way to see if the issue persists...

I shall report in this comment as I tested latest GO version:

New batch file for latest go version:

SetupGOVersion1.24.3v1.bat

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

:: Define base folder
SET GO_VERSION=version 1.24.3
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.24.3\GOPATH"
go env -w GOCACHE="G:\GOFOLDERS\version 1.24.3\GOCACHE"
go env -w GOMODCACHE="G:\GOFOLDERS\version 1.24.3\GOMODCACHE"
go env -w GOROOT="G:\GOFOLDERS\version 1.24.3\GOROOT"
go env -w GOBIN="G:\GOFOLDERS\version 1.24.3\GOBIN"
go env -w GOENV="G:\GOFOLDERS\version 1.24.3\GOENV"

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

Execution leads to:

Setting up Go environment for version 1.24.3...
warning: go env -w GOPATH=... does not override conflicting OS environment variable
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
warning: go env -w GOCACHE=... does not override conflicting OS environment variable
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
warning: go env -w GOROOT=... does not override conflicting OS environment variable
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
warning: go env -w GOBIN=... does not override conflicting OS environment variable
go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid.
go: GOENV can only be set using the OS environment
Setup complete! Restart your shell to apply changes.
Press any key to continue . . .

^ Seems normal, I might change these environment variables in windows 11 manually or maybe this can be automated as well.

After running this batchfile the environment variables keep pointing to the older version, no problem, I will update them and make them point to the new version.

Switch batchfile create:

SwitchToGOVersion1.24.3v1.bat

@echo off

echo Switching to Go environment 1.24.3...

:: Set up Go environment variables
setx GOBIN "G:\GOFOLDERS\version 1.24.3\GOBIN"
setx GOCACHE "G:\GOFOLDERS\version 1.24.3\GOCACHE"
setx GOENV "G:\GOFOLDERS\version 1.24.3\GOENV"
setx GOPATH "G:\GOFOLDERS\version 1.24.3\GOPATH"
setx GOROOT "G:\GOFOLDERS\version 1.24.3\GOROOT"

:: Alert user to update PATH manually
echo ======================================================
echo  IMPORTANT: Please update the PATH environment variable
echo  in Windows manually to include:
echo  G:\GOFOLDERS\version 1.24.3\GOROOT\bin
echo  G:\GOFOLDERS\version 1.24.3\GOBIN
echo  You can do this via:
echo  Control Panel > System > Advanced System Settings
echo  Click "Environment Variables" > Edit "Path"
echo ======================================================

echo Go environment updated successfully! Restart your terminal.
pause

Batch file updated to prevent creating empty files because of >

@echo off

echo Switching to Go environment 1.24.3...

:: Set up Go environment variables
setx GOBIN "G:\GOFOLDERS\version 1.24.3\GOBIN"
setx GOCACHE "G:\GOFOLDERS\version 1.24.3\GOCACHE"
setx GOENV "G:\GOFOLDERS\version 1.24.3\GOENV"
setx GOPATH "G:\GOFOLDERS\version 1.24.3\GOPATH"
setx GOROOT "G:\GOFOLDERS\version 1.24.3\GOROOT"

:: Alert user to update PATH manually
echo ======================================================
echo  IMPORTANT: Please update the PATH environment variable
echo  in Windows manually to include:
echo  G:\GOFOLDERS\version 1.24.3\GOROOT\bin
echo  G:\GOFOLDERS\version 1.24.3\GOBIN
echo  You can do this via:
echo  Control Panel  System  Advanced System Settings
echo  Click "Environment Variables"  Edit "Path"
echo ======================================================

echo Go environment updated successfully! Restart your terminal.
pause

Output/Result of switch batch file:

Switching to Go environment 1.24.3...

SUCCESS: Specified value was saved.

SUCCESS: Specified value was saved.

SUCCESS: Specified value was saved.

SUCCESS: Specified value was saved.

SUCCESS: Specified value was saved.
======================================================
 IMPORTANT: Please update the PATH environment variable
 in Windows manually to include:
 You can do this via:
======================================================
Go environment updated successfully! Restart your terminal.
Press any key to continue . . .

Environment variables indeed changed.

Manually changed the folder in PATH.

(Extracting new GO version into GOROOT (takes 2 minutes on a harddisk because of many tiny files, next moving go to GOROOT, deleting GO folder, these operations bit risky cause of selection risks... but so far so good it seems.)

Opening new powershell and running GO version and GO env to check:

GO VERSION output:

PS G:\GOFOLDERS> go version
go version go1.24.3 windows/amd64

GO ENV output:

PS G:\GOFOLDERS> go version
go version go1.24.3 windows/amd64
PS G:\GOFOLDERS> go env
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=G:\GOFOLDERS\version 1.24.3\GOBIN
set GOCACHE=G:\GOFOLDERS\version 1.24.3\GOCACHE
set GOCACHEPROG=
set GODEBUG=
set GOENV=G:\GOFOLDERS\version 1.24.3\GOENV
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=G:\Temp\go-build2172701346=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=G:\GOFOLDERS\version 1.24.3\GOPATH\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=G:\GOFOLDERS\version 1.24.3\GOPATH
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=G:\GOFOLDERS\version 1.24.3\GOROOT
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\skybu\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=G:\GOFOLDERS\version 1.24.3\GOROOT\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.3
set GOWORK=
set PKG_CONFIG=pkg-config
PS G:\GOFOLDERS>

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

PS G:\GOFOLDERS> go env -w GOFLAGS="-mod=vendor"
go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function.
PS G:\GOFOLDERS>

Trying to correct this error by copieing env file:

Updated env file:

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

Trying again for testing purposes to see if env file is working correctly:

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

same error, trying again with new shell:

Issues remains:

PS G:\GOFOLDERS> go env -w GOFLAGS="-mod=vendor"
go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function.
PS G:\GOFOLDERS>

^ Strange.

@SkybuckFlying SkybuckFlying changed the title go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. May 13, 2025
@SkybuckFlying SkybuckFlying changed the title go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. WAS: go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. NOW: 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. May 13, 2025
@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Conclusion both versions of GO do not seem to handle moving the env file to a different drive/folder correctly ?!?

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Even after moving the file back/re-creating it in:

C:\Users\skybu\AppData\Roaming\go

and changing the GOENV environement variable to point to it:

PS G:\GOFOLDERS> go env -w GOFLAGS="-mod=vendor"
go: reading go env config: read C:\Users\skybu\AppData\Roaming\go: Incorrect function.
PS G:\GOFOLDERS>

The problem remains ?! Weird !

@gabyhelp gabyhelp added the Question Issues that are questions about using Go. label May 13, 2025
@SkybuckFlying
Copy link
Author

AI suggests checking permissions, seems fine:

PS G:\GOFOLDERS> icacls "C:\Users\skybu\AppData\Roaming\go"
C:\Users\skybu\AppData\Roaming\go NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
BUILTIN\Administrators:(I)(OI)(CI)(F)
SuperPC2023\skybu:(I)(OI)(CI)(F)

Successfully processed 1 files; Failed processing 0 files
PS G:\GOFOLDERS>

Also it has A flag from another command...

@SkybuckFlying
Copy link
Author

Also notice how a new folder is being used: GOTELEMETRYDIR... I tried adding this to environement variables has no effect, so the only way to prevent writing to C again is to turn this off.

@seankhliao
Copy link
Member

I'm not sure how, but "Incorrect function" is something returned directly from windows, it's not something we can help you with.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2025
@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Trying out latest go version 1.24.3 for gopherjs leads to:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS G:\Junk\test vite to js conversion> gopherjs build -v -o ./cmd/gvite/output.js ./cmd/gvite --tags '!storage!'
GOOS is not supported, the supported GOOS values are linux and darwin. The GopherJS is falling back to GOOS=linux
GopherJS 1.17.2+go1.17.9 requires a Go 1.17.x distribution, but found version go1.24.3
time 2025-04-30T18:13:34Z

GopherJS 1.17.2+go1.17.9 requires a Go 1.17.x distribution, but found version go1.24.3
time 2025-04-30T18:13:34Z

PS G:\Junk\test vite to js conversion>

So this does show the need to switch GO versions to use this tool.

@SkybuckFlying
Copy link
Author

Seems like using latest installed wrong version:

go install github.com/gopherjs/gopherjs@latest

PS G:\Junk\test vite to js conversion> gopherjs version
GOOS is not supported, the supported GOOS values are linux and darwin. The GopherJS is falling back to GOOS=linux
GopherJS 1.17.2+go1.17.9
PS G:\Junk\test vite to js conversion>

A beta version should be installed instead...

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Better to install beta version:

PS G:\Junk\test vite to js conversion> go install github.com/gopherjs/[email protected]

Not sure what happens, maybe it overwrites older version...


PS G:\Junk\test vite to js conversion> go install github.com/gopherjs/[email protected]
go: downloading github.com/gopherjs/gopherjs v1.19.0-beta1
go: downloading golang.org/x/sync v0.3.0
go: downloading golang.org/x/tools v0.11.0
go: downloading github.com/visualfc/goembed v0.3.3
go: downloading github.com/evanw/esbuild v0.18.0
go: downloading golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
go: downloading github.com/fsnotify/fsnotify v1.5.1
go: downloading golang.org/x/sys v0.10.0
# github.com/gopherjs/gopherjs
link: github.com/visualfc/goembed/parser: invalid reference to go/build.parseGoEmbed
PS G:\Junk\test vite to js conversion>

Seems new problem^

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Will try switching back to older version, to continue my attempt at trying out GopherJS, just took a detour to try out different go versions to see what happens and also prevent writes to C drive... however GopherJS also has it's own CACHE and should be changed to, to not use C drive...

@SkybuckFlying
Copy link
Author

New switch batch file:

Changing 1.19 (.last) to 1.19.13 for more clearity which exact 1.19 version was used, in case I want to try out other 1.19 versions ! ;)

@echo off

echo Switching to Go environment 1.19.13...

:: Set up Go environment variables
setx GOBIN "G:\GOFOLDERS\version 1.19.13\GOBIN"
setx GOCACHE "G:\GOFOLDERS\version 1.19.13\GOCACHE"
setx GOENV "G:\GOFOLDERS\version 1.19.13\GOENV"
setx GOPATH "G:\GOFOLDERS\version 1.19.13\GOPATH"
setx GOROOT "G:\GOFOLDERS\version 1.19.13\GOROOT"

:: Alert user to update PATH manually
echo ======================================================
echo  IMPORTANT: Please update the PATH environment variable
echo  in Windows manually to include:
echo  G:\GOFOLDERS\version 1.19.13\GOROOT\bin
echo  G:\GOFOLDERS\version 1.19.13\GOBIN
echo  You can do this via:
echo  Control Panel  System  Advanced System Settings
echo  Click "Environment Variables"  Edit "Path"
echo ======================================================

echo Go environment updated successfully! Restart your terminal.
pause

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

Re-installing gopherjs into go version 1.19.13:

PS G:\Junk\test vite to js conversion> go install github.com/gopherjs/[email protected]
go: downloading github.com/gopherjs/gopherjs v1.19.0-beta1
go: downloading golang.org/x/sync v0.3.0
go: downloading github.com/sirupsen/logrus v1.8.1
go: downloading github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c
go: downloading github.com/spf13/cobra v1.2.1
go: downloading github.com/fsnotify/fsnotify v1.5.1
go: downloading github.com/spf13/pflag v1.0.5
go: downloading golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
go: downloading github.com/visualfc/goembed v0.3.3
go: downloading golang.org/x/tools v0.11.0
go: downloading github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86
go: downloading github.com/evanw/esbuild v0.18.0
go: downloading golang.org/x/sys v0.10.0
go: downloading github.com/inconshreveable/mousetrap v1.0.0
PS G:\Junk\test vite to js conversion>

and running GopherJS:

PS G:\Junk\test vite to js conversion> gopherjs build -v -o ./cmd/gvite/output.js ./cmd/gvite --tags '!storage!'

ok tool is working... now I go edit source code some more to nil output platform specific windows code and then hopefully I can see if this gopherjs can actually convert some go code to js, then I will ask AI to modify this project to try and make GoToDelphi a reality, it will probably fail but interesting to try.

Example of gopherjs output:

github.com/vitelabs/go-vite/v2/common/upgrade
github.com/syndtr/goleveldb/leveldb/util
github.com/syndtr/goleveldb/leveldb/cache
github.com/syndtr/goleveldb/leveldb/comparer
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:107:16: undeclared name: newFileLock
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:192:3: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:267:12: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:272:12: undeclared name: syncDir
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:555:9: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:591:13: undeclared name: syncDir
PS G:\Junk\test vite to js conversion>

@SkybuckFlying
Copy link
Author

Cannot edit this location directly, solution could be to use "go mod vendor" to move to editable location.

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

PS G:\Junk\test vite to js conversion> go mod vendor
go: downloading github.com/aead/ecdh v0.2.0
go: downloading gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
go: downloading golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
go: downloading github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6
go: downloading github.com/tklauser/go-sysconf v0.3.5
go: downloading github.com/go-ole/go-ole v1.2.1
go: downloading github.com/tklauser/numcpus v0.2.2
PS G:\Junk\test vite to js conversion>

@SkybuckFlying
Copy link
Author

Re-running:

PS G:\Junk\test vite to js conversion> gopherjs build -v -o ./cmd/gvite/output.js ./cmd/gvite --tags '!storage!'
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:107:16: undeclared name: newFileLock
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:192:3: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:267:12: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:272:12: undeclared name: syncDir
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:555:9: undeclared name: rename
..\..\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:591:13: undeclared name: syncDir
PS G:\Junk\test vite to js conversion>

Doesn't seem to use vendor anymore... before setting everything to G: drive, at least it seemed to do that...

@SkybuckFlying
Copy link
Author

Maybe this helps:

PS G:\Junk\test vite to js conversion> go env | grep GOFLAGS
STDIN
set GOFLAGS=
PS G:\Junk\test vite to js conversion> go build -mod=vendor
PS G:\Junk\test vite to js conversion>

@SkybuckFlying
Copy link
Author

This proves, GO is shit, constantly wrestling with this automated environment is counter productive as far as I am concerned:

S G:\Junk\test vite to js conversion> gopherjs build -v -o ./cmd/gvite/output.js ./cmd/gvite --tags '!storage!'
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:107:16: undeclared name: newFileLock
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:192:3: undeclared name: rename
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:267:12: undeclared name: rename
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:272:12: undeclared name: syncDir
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:555:9: undeclared name: rename
....\GOFOLDERS\version 1.19.13\GOPATH\pkg\mod\github.com\syndtr\[email protected]\leveldb\storage\file_storage.go:591:13: undeclared name: syncDir
PS G:\Junk\test vite to js conversion>

Might still be interesting for larger projects, but so far it's POOP :P*

Too complex, too many issues, too limited, too confusing, automation is bad, give control back to the programmer, KISS.

Keep It Simple Stupid.

@SkybuckFlying
Copy link
Author

SkybuckFlying commented May 13, 2025

I tried phind.com AI could not solve it, Co-Pilot could not solve it.

However google gemini seemed to solve it with my help, I noticed how it mention a file... I thought that is odd, I set it to a folder.

So apperently GOENV must be set to a file and not a folder. Not tested yet, but here is gemini's explanation:

(The root cause the way I see it is: GO does not explain properly how to set this environment variable and it is INCONSISTENT with the rest of the design which sets "stuff" to folders !!!)

"
No GOENV is the folder, it's not the file should GOENV environment variable be set to the FILE and not the folder ?

You've hit on a key point!

You are correct. The environment variable GOENV (which you can inspect by typing go env GOENV in your terminal) should point to a configuration file, not a directory.

The error message go: reading go env config: read G:\GOFOLDERS\version 1.19.13\GOENV: The handle is invalid. indicates that Go is attempting to read what it thinks is its environment configuration file. It's trying to open and read from the path G:\GOFOLDERS\version 1.19.13\GOENV.

If G:\GOFOLDERS\version 1.19.13\GOENV is actually a folder on your system, then the operating system will return an "invalid handle" error when a program tries to read it as if it were a file. This perfectly explains the error message you're seeing.

Here's a breakdown:

What GOENV (the variable) is:
    When you run go env, it lists various Go environment variables. One of these is GOENV.
    The value of GOENV (e.g., C:\Users\YourUser\AppData\Roaming\go\env on Windows, or ~/.config/go/env on Linux/macOS) is the path to the user-specific Go environment configuration file.
    This file is where settings changed by go env -w (like GOPATH, GOPROXY, or even GOROOT if not overridden by an OS variable) are stored.

Why your situation is problematic:
    You have a folder named GOENV located at G:\GOFOLDERS\version 1.19.13\GOENV.
    It seems Go, for some reason, is being led to believe that this specific path is the environment configuration file it should be reading. This is highly unusual. The GOENV file is not typically stored inside the GOROOT directory.

Possible Reasons for this Misdirection:

The Conflicting OS GOROOT: The warning warning: go env -w GOROOT=... does not override conflicting OS environment variable is still very relevant. If your operating system's GOROOT variable is set, and perhaps set incorrectly or in a way that confuses Go's path resolution, it might indirectly lead Go to try and find its GOENV configuration file in an unexpected location like inside the GOROOT path you are specifying.
A Misconfigured GOENV Variable Itself: While less likely if you haven't manually set it, it's theoretically possible that the GOENV variable (the one that tells Go where to find its config file) has somehow been explicitly set to point to G:\GOFOLDERS\version 1.19.13\GOENV. You can check this by typing go env GOENV in your terminal.
Corrupted Go Installation or State: There might be some corruption in your Go toolchain's understanding of its own configuration paths.

What you should do:

Address the OS GOROOT Conflict (Highest Priority):
    As mentioned before, go to your Windows System Environment Variables.
    Delete any existing GOROOT variable found in either "User variables" or "System variables". This is the most common cause of such conflicts.
    Restart your PowerShell terminal (or even your PC) for the changes to take effect.

Verify the Actual GOENV File Path:
    Open a new PowerShell terminal.
    Type go env GOENV.
    This will show you where Go expects to find its environment configuration file. This path should point to a file. If this path itself is G:\GOFOLDERS\version 1.19.13\GOENV, then that's the immediate problem source.

Rename Your Folder:
    The folder G:\GOFOLDERS\version 1.19.13\GOENV should ideally not be named GOENV if it's part of your Go SDK installation structure, as this name has a special meaning for Go's environment configuration file. However, standard Go distributions do not have a folder named GOENV directly under GOROOT. This folder might be something you created. If it doesn't contain critical Go SDK files (which it shouldn't if it's just a regular folder you made), consider renaming it to avoid confusion.

Ensure GOROOT points to the Go SDK root:
    GOROOT should point to the directory that contains bin, src, pkg, etc. for your Go 1.19.13 installation. So, G:\GOFOLDERS\version 1.19.13 should be this root directory.

Let Go Manage GOROOT if Possible:
    For modern Go, you usually don't need to set GOROOT manually if the go executable is in your PATH. After clearing the OS GOROOT and ensuring G:\GOFOLDERS\version 1.19.13\bin is in your PATH, Go should be able to find itself.
    Then, try go version and go env.

In summary:

The immediate cause of the "handle is invalid" error is that Go is trying to read a directory (G:\GOFOLDERS\version 1.19.13\GOENV) as if it were its configuration file. The most likely reason it's looking there is due to the conflicting OS-level GOROOT variable confusing its path resolution, or a less likely direct misconfiguration of the GOENV variable itself.

Start by removing the GOROOT from your system environment variables. This often resolves these kinds of confusing behaviors.
"

@SkybuckFlying
Copy link
Author

Finally problem solved, only took me like half a day ! LOL ! HAHA So much for automation:

GOENV set to:

G:\GOFOLDERS\version 1.19.13\GOENV\env

PS G:\GOFOLDERS> go env -w GOFLAGS=-mod=vendor
PS G:\GOFOLDERS> go env GOFLAGS
-mod=vendor
PS G:\GOFOLDERS>

(Probably some unix programmer which was confused between a folder and a file on windows, or this some ancient code/design which hasn't been checked/tested/streamlined in quite a while or afraid to break this, bye for now !)

@SkybuckFlying SkybuckFlying changed the title WAS: go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. NOW: 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. WAS: go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. NOW: 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. SOLVED, GOENV must be set to file instead of folder: G:\GOFOLDERS\version 1.19.13\GOENV\env May 13, 2025
@SkybuckFlying
Copy link
Author

Batch file examples correct:

SetupGOVersion1.24.3.bat

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

:: Define base folder
SET GO_VERSION=version 1.24.3
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.24.3\GOPATH"
go env -w GOCACHE="G:\GOFOLDERS\version 1.24.3\GOCACHE"
go env -w GOMODCACHE="G:\GOFOLDERS\version 1.24.3\GOMODCACHE"
go env -w GOROOT="G:\GOFOLDERS\version 1.24.3\GOROOT"
go env -w GOBIN="G:\GOFOLDERS\version 1.24.3\GOBIN"
:: Must be set to a file and not a folder
go env -w GOENV="G:\GOFOLDERS\version 1.24.3\GOENV\env"

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

SwitchToGOVersion1.24.3.bat:

@echo off

echo Switching to Go environment 1.24.3...

:: Set up Go environment variables
setx GOBIN "G:\GOFOLDERS\version 1.24.3\GOBIN"
setx GOCACHE "G:\GOFOLDERS\version 1.24.3\GOCACHE"
:: Must be set to a file and not a folder
setx GOENV "G:\GOFOLDERS\version 1.24.3\GOENV\env"
setx GOPATH "G:\GOFOLDERS\version 1.24.3\GOPATH"
setx GOROOT "G:\GOFOLDERS\version 1.24.3\GOROOT"

:: Alert user to update PATH manually
echo ======================================================
echo  IMPORTANT: Please update the PATH environment variable
echo  in Windows manually to include:
echo  G:\GOFOLDERS\version 1.24.3\GOROOT\bin
echo  G:\GOFOLDERS\version 1.24.3\GOBIN
echo  You can do this via:
echo  Control Panel  System  Advanced System Settings
echo  Click "Environment Variables"  Edit "Path"
echo ======================================================

echo Go environment updated successfully! Restart your terminal.
pause

Untested but should now work.

@SkybuckFlying
Copy link
Author

LOL new problem, running simple command:

PS G:\Junk\test vite to js conversion> go mod vendor
: The filename, directory name, or volume label syntax is incorrect..19.13\GOMODCACHE
PS G:\Junk\test vite to js conversion>

Strange... it also cuts it off, highly dumb and annoying, what a shit environment this go is...

@SkybuckFlying
Copy link
Author

Apperently another environment variable must be set to make GO work, this is very poorly documented and scatter all over the place:

GOMODCACHE must be set as well:

G:\GOFOLDERS\version 1.19.13\GOMODCACHE

I am not going to re-post the batch files, I am getting tired of it.

@golang golang locked as spam and limited conversation to collaborators May 13, 2025
@seankhliao seankhliao changed the title WAS: go: reading go env config: read G:\GOFOLDERS\version 1.19\GOENV: The handle is invalid. NOW: 1.24.3: go: reading go env config: read G:\GOFOLDERS\version 1.24.3\GOENV: Incorrect function. SOLVED, GOENV must be set to file instead of folder: G:\GOFOLDERS\version 1.19.13\GOENV\env cmd/go: poor error message for misseting GOENV on windows May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question Issues that are questions about using Go.
Projects
None yet
Development

No branches or pull requests

3 participants