Skip to content
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

VSCode installed, but winget can't execute code --version #720

Closed
2 of 4 tasks
derkrasseleo opened this issue Feb 26, 2024 · 14 comments · Fixed by #750
Closed
2 of 4 tasks

VSCode installed, but winget can't execute code --version #720

derkrasseleo opened this issue Feb 26, 2024 · 14 comments · Fixed by #750
Labels
C-bug Something isn't working help wanted Extra attention is needed P-Windows Windows issue

Comments

@derkrasseleo
Copy link

derkrasseleo commented Feb 26, 2024

Erroneous Behavior

Visual Studio Code extensions failed:
   0: Failed to execute `code --version`
   1: program not found

Expected Behavior

program found

Steps to reproduce

run topgrade in powershell on windows 11

Possible Cause (Optional)

I can only say that there's no differnce if I'm running topgrade in administrative shell or not.

Problem persists without calling from topgrade

  • Yes
  • No

Did you run topgrade through Remote Execution

  • Yes
  • No

Configuration file (Optional)

Additional Details

  • Operation System/Version
    Windows 11 Home Version 10.0.22631 Build 22631

  • Installation
    winget

  • Topgrade version (topgrade -V)
    14.0.1

Verbose Output (topgrade -v)

DEBUG Step "Visual Studio Code extensions"
DEBUG Detected "C:\\Users\\leoch\\AppData\\Local\\Programs\\Microsoft VS Code\\bin\\code.CMD" as "code"
DEBUG Executing command `code --version`
DEBUG Step "Visual Studio Code extensions" failed:
   0: Failed to execute `code --version`
   1: program not found

Location:
src\steps\generic.rs:352
Visual Studio Code extensions failed:
0: Failed to execute code --version
1: program not found

Location:
src\steps\generic.rs:352
Retry? (y)es/(N)o/(s)hell/(q)uit

@derkrasseleo derkrasseleo added the C-bug Something isn't working label Feb 26, 2024
@SteveLauC
Copy link
Member

What is the output of code --version if you directly do it in your shell?

@derkrasseleo
Copy link
Author

derkrasseleo commented Feb 26, 2024

PS C:\Users\leoch> code --version
1.86.2
903b1e9d8990623e3d7da1df3d33db3e42d80eda
x64

seems to be the most recent version

@derkrasseleo
Copy link
Author

derkrasseleo commented Feb 26, 2024

Does topgrade expect a special PATH variable for code ?

Mine is a user variable that points to C:\Users\leoch\AppData\Local\Programs\Microsoft VS Code\bin

@SteveLauC
Copy link
Member

Does topgrade expect a special PATH variable for code ?

No

DEBUG Detected "C:\Users\leoch\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD" as "code"

From the log, Topgrade has successfully found the code binary, I have no idea why it didn't work in the Topgrade code...

@SteveLauC
Copy link
Member

SteveLauC commented Feb 26, 2024

Mine is a user variable that points to C:\Users\leoch\AppData\Local\Programs\Microsoft VS Code\bin

Interesting, perhaps the Rust std::process::Command type won't automatically dereference links on Windows?

@derkrasseleo
Copy link
Author

No clue, sorry, I don't have any experience with rust

@loehden
Copy link

loehden commented Mar 5, 2024

I got exactly the same issue, no matter whether I run it from powershell or from cmd.

Additional Details


  • Operation System/Version
    Windows 11 Pro 23H2, Build 22631.3235

  • Installation
    cargo

  • Topgrade version (topgrade -V)
    14.0.1

Verbose Output (topgrade -v)


DEBUG Step "Visual Studio Code extensions"
DEBUG Detected "C:\\Program Files\\Microsoft VS Code\\bin\\code.CMD" as "code"
DEBUG Executing command `code --version`
DEBUG Step "Visual Studio Code extensions" failed:
   0: Failed to execute `code --version`
   1: program not found

Location:
   C:\Users\Xx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\topgrade-14.0.1\src\steps\generic.rs:352
Visual Studio Code extensions failed:
   0: Failed to execute `code --version`
   1: program not found

Location:
   C:\Users\Xx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\topgrade-14.0.1\src\steps\generic.rs:352

@Lim-Dul
Copy link

Lim-Dul commented Mar 9, 2024

I have the exact same issue on:
Edition Windows 11 Pro
Version 23H2
OS build 22631.3235

VSCode Version 1.87.1

Topgrade Version 14.0.1

The additional information I can perhaps provide is that the issues started with topgrade 14.* without any changes to my setup. The issue also occurs on a second machine of mine which is configured quite differently to the one I'm posting this from.

I have redownloaded Topgrade 13.0.0 and topgrade --only vscode finished just fine.
In either case just typing in code --version in the console runs just fine. Something broke between topgrade v13 and v14...

@SteveLauC SteveLauC added P-Windows Windows issue help wanted Extra attention is needed labels Mar 9, 2024
@SteveLauC
Copy link
Member

The additional information I can perhaps provide is that the issues started with topgrade 14.0.1 without any changes to my setup. The issue also occurs on a second machine of mine which is configured quite differently to the one I'm posting this from.

Thanks for this info!


My thought on this issue is that it should be something specific to Windows, I have no idea why we can not execute code --version in Rust code...

How did you guys get your VSCode installed, maybe I will set up a Windows machine to give it a test.

@SteveLauC SteveLauC mentioned this issue Mar 9, 2024
@Lim-Dul
Copy link

Lim-Dul commented Mar 9, 2024

On both machines VSCode has been installed through chocolatey but the installation path is the default one. Unlike scoop or something no shims seem to be created, just the official installer downloaded and executed resulting in:

❯ Get-Command code

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     code.cmd                                           0.0.0.0    C:\Program Files\Microsoft VS Code\bin\code.cmd

One observation is that this is a batch script, not an executable with the contents of:

@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal

But this doesn't explain why code --version runs OK and why it works in topgrade v13. Maybe the paths somehow changed between VSCode versions as you'll note that code.exe is actually located one directory above what the code command (and correspondingly code.cmd) actually executes.

Update: I checked the source code between v13 and v14 and apparently the difference is that in v13 there was no attempt to call code --version to handle exceptions when VSCode was too old to have an Extension Update command. v13, as far as I can tell, handled VSCode Extension updates by just getting a list of installed ones and then looping through the list via --install-extension. Of course this is much clunkier than using the new update command but it worked. No idea why calling code --version doesn't work although this, again, might be tied to this not actually being an executable but rather a batch script calling an executable. I gather the batch script processing doesn't work if it is called from topgrade.
A hacky solution would be calling code.exe one directory up from what the path says it's located at? 🤔
A GIGA hacky solution would be calling the command through cmd or pwsh instead of directly to ensure script processing but this is a Windows-only problem and would break the generic-ness of the codebase. Or one would have to have branching based on OS in this case.

@SteveLauC
Copy link
Member

Update: I checked the source code between v13 and v14 and apparently the difference is that in v13 there was no attempt to call code --version to handle exceptions

Right, this version check was introduced in v14.x.x

Thanks for the info, I will try to give it a test.

@yuma140902
Copy link

Hello. I think it may be related to rust-lang/rust#37519

@SteveLauC
Copy link
Member

Hello. I think it may be related to rust-lang/rust#37519

Thanks for bringing this up! I will take a closer look this weekend

@SteveLauC
Copy link
Member

SteveLauC commented Mar 24, 2024

Ok, I am able to reproduce this issue in my Windows VM:

  • Windows 10 home edition
  • VS Code 1.87.2 (downloaded from browser)
  • Rust 1.77
PS C:\Users\steve\Desktop\rust> get-command code

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     code.cmd                                           0.0.0.0    C:\Users\steve\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd


PS C:\Users\steve\Desktop\rust> get-content 'C:\Users\steve\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd'
@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal
PS C:\Users\steve\Desktop\rust>

Using std::process::Command to involve the code command won't work cause the binary cannot be found, from this comment, the which() function provided by the which crate works in a way closer to PowerShell, and it indeed works in my VM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Something isn't working help wanted Extra attention is needed P-Windows Windows issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants