Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Error: TypeError: Invalid Version: undefined #2770

Closed
ransombriggs opened this issue Sep 20, 2019 · 32 comments
Closed

Error: TypeError: Invalid Version: undefined #2770

ransombriggs opened this issue Sep 20, 2019 · 32 comments

Comments

@ransombriggs
Copy link

Steps to Reproduce:

  1. Ubuntu
-> % cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
  1. Visual Studio
-> % code --version      
1.38.1
b37e54c98e1a74ba89e03073e5a3761284e3ffb0
x64
  1. Go
-> % go version
go version go1.12.9 linux/amd64
  1. main.go
-> % cat main.go 
package main

func main() {

}
  1. Save main.go
    image

Debugging

I found that if I turned off buildOnSave and vetOnSave that the error goes away if that helps at all with debugging.

{
    "go.buildOnSave": "off",
    "go.vetOnSave": "off"
}
@ramya-rao-a
Copy link
Contributor

Are you able to see this consistently? If yes, then can you share the stack trace for this error? You can find this in one of 2 places

  • The logs for the extension host
    • Select Output from the View menu, and then select Log (Extension Host) from the drop down on the top right corner of the output panel
  • The dev tools for VS Code
    - Run the command Developer: Toggle Developer Tools

In case there is too much noise in these logs, you can clear them and do what is needed to replicate the issue to see the corresponding logs

@mrpanc
Copy link

mrpanc commented Sep 23, 2019

Same error. "Error: TypeError: Invalid Version: undefined" is the only thing i've got. There is no other log or more information.

@mrpanc
Copy link

mrpanc commented Sep 23, 2019

It happens after upgrading to the latest version.

@ramya-rao-a
Copy link
Contributor

@mrpanc Did you try the output panel or the console as suggested in #2770 (comment) for more information?

@ramya-rao-a
Copy link
Contributor

@mrpanc Are you also able to get around the error by disabling the build on save and vet on save feature like @ransombriggs ?

@mrpanc, @ransombriggs Can you share the version of Go you are using? Also share any Go related settings you might have added/edited. You can get these by running the command Preferences: Open Settings (JSON)

@stamblerre This is most likely coming from the semver dependency that was added in the last release. There are 2 locations in the semver library where this error is thrown from:

Since the error is having undefined, the first line above is the most likely suspect.

If either @mrpanc or @ransombriggs can share the stack trace, then that would be most helpful. Meanwhile, we can start the investigation around the build & vet on save features

@lenmore
Copy link

lenmore commented Sep 23, 2019

Same error. here is the log:

[2019-09-23 16:18:06.673] [exthost] [error] [ms-vscode.Go] provider FAILED
[2019-09-23 16:18:06.673] [exthost] [error] TypeError: Invalid Version: undefined
at new SemVer (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:314:11)
at compare (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:647:10)
at Function.lt (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:688:10)
at GoVersion.lt (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/out/src/util.js:111:23)
at Object. (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/out/src/goModules.js:63:23)
at Generator.next ()
at fulfilled (/home/my/.vscode/extensions/ms-vscode.go-0.11.6/out/src/goModules.js:9:58)

@ransombriggs
Copy link
Author

@ramya-rao-a found in the developer tools

mainThreadExtensionService.ts:65 TypeError: Invalid Version: undefined
	at new SemVer (/home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/node_modules/semver/semver.js:314)
	at compare (/home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/node_modules/semver/semver.js:647)
	at Function.lt (/home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/node_modules/semver/semver.js:688)
	at GoVersion.lt (/home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/out/src/util.js:111)
	at /home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/out/src/goModules.js:63
	at Generator.next (<anonymous>)
	at fulfilled (/home/rbriggs/.vscode/extensions/ms-vscode.go-0.11.5/out/src/goModules.js:9)

@ramya-rao-a
Copy link
Contributor

Awesome, thanks for the stack traces!!

@lenmore, @ransombriggs Can you share the version of Go you are using? Also share any Go related settings you might have added/edited. You can get these by running the command Preferences: Open Settings (JSON)

@stamblerre Based on the above, I have narrowed it down to https://github.com/microsoft/vscode-go/blob/0.11.5/src/goModules.ts#L56 in our code and https://github.com/npm/node-semver/blob/0eeceecfba490d136eb3ccae3a8dc118a28565a0/semver.js#L647 in semver

@ransombriggs
Copy link
Author

-> % which go
/snap/bin/go
-> % go version
go version go1.12.9 linux/amd64
-> % cat ~/.config/Code/User/settings.json
{
}

@stamblerre
Copy link
Contributor

I sent a PR to add some additional testing and error handling, but I imagine that something is going wrong when we parse the user's Go version. If it fails the first time for whatever reason, we don't retry, which I suppose might be causing this error.

@tomjowitt
Copy link

tomjowitt commented Sep 24, 2019

I have the same issue on Ubuntu. Like @ransombriggs I can remove it by changing the on save settings for vet/build.

Ubuntu:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.04
DISTRIB_CODENAME=disco
DISTRIB_DESCRIPTION="Ubuntu 19.04"

Go Version:

$ go version
go version go1.12.9 linux/amd64

Code Version:

$ code --version
1.38.1
b37e54c98e1a74ba89e03073e5a3761284e3ffb0
x64

settings.json

{
    "go.toolsGopath": "/home/tom/go/",
    "go.buildOnSave": "off",
    "go.vetOnSave": "off",
    "go.coverOnSave": true,
    "go.testOnSave": true
}

The log output is as follows:

[2019-09-24 10:26:11.765] [exthost] [error] [ms-vscode.Go] provider FAILED
[2019-09-24 10:26:11.765] [exthost] [error] TypeError: Invalid Version: undefined
	at new SemVer (/home/tom/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:314:11)
	at compare (/home/tom/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:647:10)
	at Function.lt (/home/tom/.vscode/extensions/ms-vscode.go-0.11.6/node_modules/semver/semver.js:688:10)
	at GoVersion.lt (/home/tom/.vscode/extensions/ms-vscode.go-0.11.6/out/src/util.js:111:23)
	at /home/tom/.vscode/extensions/ms-vscode.go-0.11.6/out/src/goModules.js:63:23
	at Generator.next (<anonymous>)
	at fulfilled (/home/tom/.vscode/extensions/ms-vscode.go-0.11.6/out/src/goModules.js:9:58)
[2019-09-24 10:26:12.735] [exthost] [error] [ms-vscode.Go] provider FAILED
[2019-09-24 10:26:12.735] [exthost] [error] undefined

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 24, 2019

Hey all,

Can you try the latest beta version (0.11.7-beta.3) of this extension and see if the issue still persists?

If the issue no longer persists, then open the console logs again and look for any logs starting with either of the below and share them please

  • Error when running the command "go version"
  • Not able to determine version from the output of the command "go version"

@tomjowitt
Copy link

@ramya-rao-a Perfect. The beta version works. Thanks so much for the speedy fix.

The extension host logs have nothing related to the version now:

[2019-09-24 12:46:02.186] [exthost] [info] extension host started
[2019-09-24 12:46:02.201] [exthost] [info] ExtensionService#_doActivateExtension ms-vscode.Go {"startup":false,"activationEvent":"onLanguage:go"}
[2019-09-24 12:46:02.201] [exthost] [info] ExtensionService#loadCommonJSModule file:///home/tom/.vscode/extensions/ms-vscode.go-0.11.7-beta.3/out/src/goMain
[2019-09-24 12:46:02.418] [exthost] [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch {"startup":true,"activationEvent":"*"}
[2019-09-24 12:46:02.418] [exthost] [info] ExtensionService#loadCommonJSModule file:///snap/code/15/usr/share/code/resources/app/extensions/debug-auto-launch/dist/extension
[2019-09-24 12:46:02.420] [exthost] [info] ExtensionService#_doActivateExtension vscode.emmet {"startup":true,"activationEvent":"*"}
[2019-09-24 12:46:02.420] [exthost] [info] ExtensionService#loadCommonJSModule file:///snap/code/15/usr/share/code/resources/app/extensions/emmet/dist/extension
[2019-09-24 12:46:02.451] [exthost] [info] ExtensionService#_doActivateExtension vscode.git {"startup":true,"activationEvent":"*"}
[2019-09-24 12:46:02.451] [exthost] [info] ExtensionService#loadCommonJSModule file:///snap/code/15/usr/share/code/resources/app/extensions/git/dist/main
[2019-09-24 12:46:02.526] [exthost] [info] ExtensionService#_doActivateExtension vscode.merge-conflict {"startup":true,"activationEvent":"*"}
[2019-09-24 12:46:02.526] [exthost] [info] ExtensionService#loadCommonJSModule file:///snap/code/15/usr/share/code/resources/app/extensions/merge-conflict/dist/extension
[2019-09-24 12:46:02.531] [exthost] [info] ExtensionService#_doActivateExtension alefragnani.project-manager {"startup":true,"activationEvent":"*"}
[2019-09-24 12:46:02.531] [exthost] [info] ExtensionService#loadCommonJSModule file:///home/tom/.vscode/extensions/alefragnani.project-manager-10.7.0/dist/extension
[2019-09-24 12:46:02.776] [exthost] [info] eager extensions activated

@tomjowitt
Copy link

Apologies, I only checked the logs and not the console dev tools:

console.ts:137 [Extension Host] Not able to determine version from the output of the command "go version":

@ransombriggs
Copy link
Author

I tried the beta and I no longer get errors and I also see the following in the dev tools

console.ts:137 [Extension Host] Not able to determine version from the output of the command "go version": 

@ramya-rao-a
Copy link
Contributor

Awesome, so looks like the go version command does not fail or give any errors, but only gives blank output, that is very sad :(

cc @stamblerre

@ziishaned
Copy link

Run into the same issue. After setting GOPATH inside .zshrc file like following solved the issue for me:

export GOPATH="$HOME/go"

@stamblerre
Copy link
Contributor

@ramya-rao-a: I think it's more likely that we are failing to find the path for the go command. I asked @jayconrod, and I don't think that the go version command would ever silently fail (golang/go#34499 is an example of a failure case; they are quite rare).

@ramya-rao-a
Copy link
Contributor

@stamblerre It is unlikely that we didn't find path to go. If that were true,

  • We would exit early in the getGoVersion() function
  • the build & vet on save features along with so many others that depend on go list would be failing

@tomjowitt
Copy link

Not sure it's related, but I'm on a fresh install and installed Go from snap for the first time. I didn't previously have any issues when I manually installed into /usr/bin or /usr/local/bin.

$ which go
/snap/bin/go

@angelo-moreira
Copy link

Don't think it is related because my GO Path is /usr/bin/go in Ubuntu 18.04 and I also get the same error message

@ramya-rao-a
Copy link
Contributor

Thanks all!

Can you confirm one more thing for me please?

  • Use the beta version of this extension
  • Turn off the language server if you are using it by setting go.useLanguageServer to false. Enable the go.buildOnSave and go.vetOnSave settings. If prompted to reload, then reload the VS Code window
  • Introduce an error in your code. Do you get the red squiggly lines showing that you have an error?
    If you do, then this proves that the extension had no trouble finding the go binary and the problem we are dealing with is indeed that go version does not return anything.

@srinathh
Copy link

Thanks all!

Can you confirm one more thing for me please?

  • Use the beta version of this extension
  • Turn off the language server if you are using it by setting go.useLanguageServer to false. Enable the go.buildOnSave and go.vetOnSave settings. If prompted to reload, then reload the VS Code window
  • Introduce an error in your code. Do you get the red squiggly lines showing that you have an error?
    If you do, then this proves that the extension had no trouble finding the go binary and the problem we are dealing with is indeed that go version does not return anything.

Ran into this problem today and using the beta version fixed it. I also ran the steps above & can confirm it works as expected

@ransombriggs
Copy link
Author

@ramya-rao-a I do not get the red squiggly after following the instructions

@tomjowitt
Copy link

@ramya-rao-a I do not get the red squiggly either and the editor reports no problems even when the code is broken.

@kumropotash1
Copy link

Can anyone confirm if installing go from Snap is causing it or not?
I installed Go from snap a couple of days ago and ran into the same problem

$ which go
/snap/bin/go

$ go version
go version go1.12.10 linux/amd64

@ramya-rao-a
Copy link
Contributor

@ransombriggs, @tomjowitt If your go.buildOnSave setting is not disabled and you are not seeing any errors being reported for code where you introduced errors, then the issue indeed is that the extension fails to find the path to the go binary...

@ramya-rao-a
Copy link
Contributor

Another way to check if the extension is able to find the Go tool or not is to run the Go: Browse Packages and see if you get an error notification. Can people on this thread try this command?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 27, 2019

The latest update (0.11.7) has the fix for this issue of TypeError showing up.
Those of you who did see this issue, I'd appreciate it if you can continue working with us to figure out why is it that the extension fails to find the Go binary in your cases.

  • Please run the command Go: Browse Packages and report back if this throws an error
  • Then, check your console by running the Developer: Toggle Developer Tools command and look for error logs Error when running the command or Not able to determine version from the output of the command.
    • If you have these logs, then it will also have the path that the extension believes to be the path for the Go binary

@tomjowitt
Copy link

Thanks for the update @ramya-rao-a.

On version 0.11.7:

Go: Browse Packages works and does not throw any errors.

Developer: Toggle Developer Tools throws the following error but does not contain a path. Anything after the colon is blank.

[Extension Host] Not able to determine version from the output of the command "go version": 

@howbazaar
Copy link

I did have this problem, and after restarting Code it has now gone away.

This got me thinking about what changed underneath.

snap info go showed me that it had refreshed four days ago, so perhaps the remembered Go that Code has referenced internally was moved underneath it.

This could probably be tested by changing the go snap to use a different release, like snap refresh go --channel 1.11, and then seeing if Code has issues.

I'm trying this just now... 🕺 ... didn't seem to impact it.

@ransombriggs
Copy link
Author

@Arghyadeb @ramya-rao-a I was able to fix this by uninstalling snap and following these instructions instead

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.