Skip to content

Opening repository in command prompt results in catastrophic error #3825

Closed

Description

@laZaru5ap

Description

Unable to open repository in command prompt from the desktop app. Restarting the app results in the same error every time.

Version

1.0.12

GitHub Desktop version: 1.0.12

OS version: Windows 6.1.7601 (Windows 7 Ultimate SP1 64-bit)

Steps to Reproduce

github error_open in command prompt

Expected behavior: Opened in command prompt

Actual behavior: Error on the desktop app

Reproduces how often: 100%

Logs

Error: spawn where ENOENT
at exports._errnoException (util.js:1050:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

Version: 1.0.12
OS: Windows 6.1.7601

Additional Information

Activity

  1. changed the title [-]Desktop App Error[/-] [+] Opening repository in command prompt results in catastrophic error[/+] on Jan 19, 2018
  2. added
    more-info-needed
    on Jan 21, 2018
  3. shiftkey commented on Jan 21, 2018

    @shiftkey
    Member

    @laZaru5ap thanks for the report.

    The code to launch cmd is rather straightforward:

    const cp = spawn('START', ['cmd'], { shell: true, cwd: path })
    

    My gut feeling is that your PATH value isn't configured as expected.

    Could you open a command prompt, run these two commands and attach the output here:

    > echo %PATH%
    > where cmd
    

    This is what it looks like on one of my developer VMs:

    Microsoft Windows [Version 10.0.16299.192]
    (c) 2017 Microsoft Corporation. All rights reserved.
    
    C:\Users\shiftkey>echo %PATH%
    C:\Program Files (x86)\Parallels\Parallels Tools\Applications;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\; ...
    
    C:\Users\shiftkey>where cmd
    C:\Windows\System32\cmd.exe
    
  4. gilmae commented on Jan 30, 2018

    @gilmae

    I'm seeing the same issue as the OP. Actually, I've seen it no matter what shell I opt for - Git Bash, Powershell, or Command Prompt.

    Microsoft Windows [Version 10.0.16299.192]
    (c) 2017 Microsoft Corporation. All rights reserved.

    C:\Users\username>where cmd
    'where' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\username>echo %PATH%
    C:\OpenSSL-Win64\bin;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\username\AppData\Local\Microsoft\WindowsApps;C:\Users\username\AppData\Local\GitHubDesktop\bin

    Manual check confirms, cmd.exe is in c:\Windows\System32

    The exact error message received is

    Error: spawn where ENOENT
    at exports._errnoException (util.js:1050:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

    Version: 1.0.13
    OS: Windows 10.0.16299

  5. shiftkey commented on Jan 30, 2018

    @shiftkey
    Member

    @gilmae thanks for the details. I think the fix for this is to provide the full path when spawning cmd.

  6. self-assigned this
    on Jan 30, 2018
  7. added
    bug
    and removed
    more-info-needed
    on Jan 30, 2018
  8. shiftkey commented on Jan 30, 2018

    @shiftkey
    Member

    @gilmae

    Actually, I've seen it no matter what shell I opt for - Git Bash, Powershell, or Command Prompt.

    This is puzzling, because Git Bash and PowerShell don't rely on PATH in the same way.

    • Git Bash should be found in the registry at HKLM\SOFTWARE\GitForWindows and looking for the install directory in the InstallDir key (source)
    • PowerShell should also be found registry for HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\PowerShell.exe and tries to replace `%SYSTEMROOT% if it's in the path (source)
    • We had some registry access issues in the past when group policy would restrict access to regedit.exe and reg.exe, but in those cases you wouldn't be able to see it in the list, which sounds different to what you're reporting about it failing to launch.

    Please open a fresh issue for either of these if they're repeatable, and provide any extra information or clues you think will help understand why they're failing to launch.

  9. shiftkey commented on Jan 30, 2018

    @shiftkey
    Member

    @gilmae so I looked over the code and we're already handling the lack of a PATH for the cmd prompt:

      const shells = [
        {
          shell: Shell.Cmd,
          path: process.env.comspec || 'C:\\Windows\\System32\\cmd.exe',
        },
      ]

    Can you tell me what the output of this command is in your Command Prompt?

    > echo %COMSPEC%
    

    If this is set to something other than C:\WINDOWS\system32\cmd.exe that's probably the root cause here. We should be falling back to the right path if that's not set, maybe we shouldn't be trusting these environment variables?

  10. gilmae commented on Jan 30, 2018

    @gilmae

    C:\Users\username>echo %COMSPEC%
    C:\WINDOWS\system32\cmd.exe

  11. shiftkey commented on Jan 30, 2018

    @shiftkey
    Member

    @gilmae nevermind, it's still totally a PATH issue. The launch steps are different to how we're resolving the shells on disk, and in some cases we just use START {command} (which relies on {command} being found on the PATH).

    export async function launch(
    foundShell: IFoundShell<Shell>,
    path: string
    ): Promise<void> {
    const shell = foundShell.shell
    if (shell === Shell.PowerShell) {
    const psCommand = `"Set-Location -LiteralPath '${path}'"`
    const cp = spawn(
    'START',
    ['powershell', '-NoExit', '-Command', psCommand],
    {
    shell: true,
    cwd: path,
    }
    )
    addErrorTracing(`PowerShell`, cp)
    } else if (shell === Shell.Hyper) {
    const cp = spawn(`"${foundShell.path}"`, [`"${path}"`], {
    shell: true,
    cwd: path,
    })
    addErrorTracing(`Hyper`, cp)
    } else if (shell === Shell.GitBash) {
    const cp = spawn(`"${foundShell.path}"`, [`--cd="${path}"`], {
    shell: true,
    cwd: path,
    })
    addErrorTracing(`Git Bash`, cp)
    } else if (shell === Shell.Cmd) {
    const cp = spawn('START', ['cmd'], { shell: true, cwd: path })
    addErrorTracing(`CMD`, cp)
    } else {
    assertNever(shell, `Unknown shell: ${shell}`)
    }

    In fact powershell also suffers from the same defect, so I'll see if I can also fix that while I'm in here. I'm not sure about Git Bash though.

  12. removed their assignment
    on Feb 1, 2018
  13. laZaru5ap commented on Feb 1, 2018

    @laZaru5ap
    Author

    @shiftkey Yes, I think it is a issue with the PATH. On its own, it works perfectly fine.

  14. added this to the 1.1.x milestone on Feb 8, 2018
  15. locked as resolved and limited conversation to collaborators on Jul 18, 2018
  16. unlocked this conversation on Sep 27, 2018
  17. removed their assignment
    on Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions