cli: gh auth login: could not prompt: The handle is invalid.

Describe the bug

I downloaded gh via chocolatey and tried to login with GitHub, but looks like its not working. When it asks for the prompt, it stops telling: could not prompt: The handle is invalid. Output of gh --version:

gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0

Steps to reproduce the behavior

  1. Type this gh auth login
  2. View the output:
? What account do you want to log into? [Use arrows to move, type to filter]
    >GitHub.com
    GitHub Enterprise Server
  1. See error: could not prompt: The handle is invalid.

Expected vs actual behavior

Expected: To have me use the arrow keys to select the hostname + the way to login, Personal Access Token or Web Actual: Stops executing with err code 1: could not prompt: The handle is invalid.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Hey all! I found out a solution, but for Git Bash! Instead of running <command>, run winpty <command>[.exe|.cmd]. In this case, winpty gh.exe auth login Or, if you are too lazy 😉 , run echo "alias <command (without options)>=\"winpty <command (without options)>\"" >> ~/.bashrc In this case: echo "alias gh=\"winpty gh.exe\"" >> ~/.bashrc

Reference(though not related): Vue.js CLI Docs (see warning)

I’m unable to navigate the menus. I get the following error when I use the arrow keys.

Unexpected Escape Sequence: ['\x1b' 'O']

macOS, zsh, iTerm2, tmux

When I installed Git for Windows, I chose not to use mintty but the regular old conhost.exe that comes with Windows

@alannt777 You’re right. This only ever happens on emulators that don’t support interactive Command line interfaces, like ConEmu(possibly via Cmder), MinTTY (Possibly via Git Bash, Cygwin and many others). While installing Git for Windows, there is an option that says, “Enable experimental support for pseudo terminals” or something similar. If we check that option, the interactive CLIs work. But as it mentions, “this option is experimental”

@ryancogswell I do not seem to get this error with gh pr create --fill 🤔

I eventually found the root of this secondary issue. gh auth login --hostname github.com --web works (lowercase “github.com”), but gh auth login --hostname GitHub.com --web (mixed case “GitHub.com”) does not work. Both commands report success, but the results from the mixed-case version are not successfully leveraged by later commands. This is regardless of the terminal/shell being used.

This issue is not confined to the gh auth login. It also happens when trying to run gh repo create.

Running the following command: $ gh repo create mzzmjd/created-via-cli --internal

Returns the error message: ? This will create 'mzzmjd/created-via-cli' in your current directory. Continue? (Y/n) The handle is invalid.

@smw4 That seems like the same issue as https://github.com/cli/cli/issues/6147, would you mind adding your system details to that issue as we have been unable to reproduce it so far.

Hey all! I found out a solution, but for Git Bash! Instead of running <command>, run winpty <command>[.exe|.cmd]. In this case, winpty gh.exe auth login …

When I try your fix, I get the following error message, which I’m having difficulty deciphering.

-> winpty gh.exe auth login
panic: interface conversion: *colorable.Writer is not terminal.FileWriter: missing method Fd

goroutine 1 [running]:
github.com/cli/cli/v2/internal/prompter.New(...)
        /home/runner/work/cli/cli/internal/prompter/prompter.go:29
github.com/cli/cli/v2/pkg/cmd/factory.newPrompter(0xc0003cf3b0)
        /home/runner/work/cli/cli/pkg/cmd/factory/default.go:117 +0xac
github.com/cli/cli/v2/pkg/cmd/factory.New({0x1f1cf54, 0x6})
        /home/runner/work/cli/cli/pkg/cmd/factory/default.go:36 +0x1cf
main.mainRun()
        /home/runner/work/cli/cli/cmd/gh/main.go:64 +0x108
main.main()
        /home/runner/work/cli/cli/cmd/gh/main.go:48 +0x19

I’m getting the exact same issue using git bash for Windows version 2.27.0.windows.1. I thought I might be able to work around it by avoiding the prompts via “gh auth login --hostname GitHub.com --web” and I got successfully through the authentication steps, but it doesn’t seem to successfully remember the authentication. When I then tried “gh pr create --fill” I received “HTTP 401: This endpoint requires you to be authenticated…”.

@shrihanDev Hi, thank you for the report! Which terminal program were you using when you were trying to authenticate? E.g. cmd.exe, PowerShell, Git Bash, Windows Terminal, etc.

I am using ZSH with MSYS2 Bash with ConEmuC64 with Cmder 😏

Also, if I use this with Cmd, then directly from MSYS2 Shell, then bash.exe executable, then zsh.exe executable, it does work 😼

I get the same error message using Git bash Version 2.28.0.windows.1

GitVersion

You don’t get the option to move the selection:

ErrorMessage