-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Comments
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
Execution leads to:
^ 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
Batch file updated to prevent creating empty files because of >
Output/Result of switch batch file:
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:
GO ENV output:
go env -w GOFLAGS="-mod=vendor" output:
Trying to correct this error by copieing env file: Updated env file:
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:
^ Strange. |
Conclusion both versions of GO do not seem to handle moving the env file to a different drive/folder correctly ?!? |
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" The problem remains ?! Weird ! |
AI suggests checking permissions, seems fine: PS G:\GOFOLDERS> icacls "C:\Users\skybu\AppData\Roaming\go" Successfully processed 1 files; Failed processing 0 files Also it has A flag from another command... |
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. |
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 |
Trying out latest go version 1.24.3 for gopherjs leads to:
So this does show the need to switch GO versions to use this tool. |
Seems like using latest installed wrong version: go install github.com/gopherjs/gopherjs@latest PS G:\Junk\test vite to js conversion> gopherjs version A beta version should be installed instead... |
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...
Seems new problem^ |
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... |
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 ! ;)
|
Re-installing gopherjs into go version 1.19.13:
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:
|
Cannot edit this location directly, solution could be to use "go mod vendor" to move to editable location. |
|
|
Maybe this helps:
|
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!' 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. |
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 !!!) " 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:
Possible Reasons for this Misdirection:
What you should do:
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. |
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 (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 !) |
Batch file examples correct: SetupGOVersion1.24.3.bat
SwitchToGOVersion1.24.3.bat:
Untested but should now work. |
LOL new problem, running simple command:
Strange... it also cuts it off, highly dumb and annoying, what a shit environment this go is... |
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. |
Go version
go version go1.19.13 windows/amd64
Output of
go env
in your module/workspace: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
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.
The text was updated successfully, but these errors were encountered: