From dc66c2a8d0efa8e358f8a48eccfabffd5c23ad93 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Oct 2026 17:05:30 +0200 Subject: [PATCH] internal/oauth: handle error when failing to open browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, pressing `ENTER` to open the browser would silently discard the error; docker login i Info → Using web-based login. To sign in with credentials on the command line, use 'docker login -u ' Your one-time device confirmation code is: VGTB-VKBG Press ENTER to open your browser or submit your device code here: https://login.docker.com/activate Waiting for authentication in the browser… With this patch, a failure is printed, so that the user can manually open the URL (or cancel the login); docker login i Info → Using web-based login. To sign in with credentials on the command line, use 'docker login -u ' Your one-time device confirmation code is: SZFX-BSGP Press ENTER to open your browser or submit your device code here: https://login.docker.com/activate Waiting for authentication in the browser… No browser found. Open the URL above manually to continue. Signed-off-by: Sebastiaan van Stijn --- internal/oauth/manager/manager.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/oauth/manager/manager.go b/internal/oauth/manager/manager.go index 9997ed5982..37bce932fa 100644 --- a/internal/oauth/manager/manager.go +++ b/internal/oauth/manager/manager.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "os" + "os/exec" "strings" "github.com/docker/cli/cli/config/credentials" @@ -124,7 +125,19 @@ func (m *OAuthManager) LoginDevice(ctx context.Context, w io.Writer) (*types.Aut if _, err := reader.ReadString('\n'); err != nil || ctx.Err() != nil { return } - _ = m.openBrowser(state.VerificationURI) + err := m.openBrowser(state.VerificationURI) + if ctx.Err() != nil { + return + } + if err != nil { + if errors.Is(err, exec.ErrNotFound) { + _, _ = fmt.Fprintln(w, "No browser found. Open the URL above manually to continue.") + } else { + _, _ = fmt.Fprintln(w, "Failed to open browser:", err) + _, _ = fmt.Fprintln(w, "Open the URL above manually to continue.") + } + return + } }() _, _ = fmt.Fprint(w, "\nWaiting for authentication in the browser…\n")