Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -314,6 +315,22 @@ func loadProfileByName(ctx context.Context, profileName string, profiler profile
return nil, nil
}

// openURLSuppressingStderr opens a URL in the browser while suppressing stderr output.
// This prevents xdg-open error messages from being displayed to the user.
func openURLSuppressingStderr(url string) error {
// Save the original stderr from the browser package
originalStderr := browserpkg.Stderr
defer func() {
browserpkg.Stderr = originalStderr
}()

// Redirect stderr to discard to suppress xdg-open errors
browserpkg.Stderr = io.Discard

// Call the browser open function
return browserpkg.OpenURL(url)
}

// getBrowserFunc returns a function that opens the given URL in the browser.
// It respects the BROWSER environment variable:
// - empty string: uses the default browser
Expand All @@ -323,10 +340,10 @@ func getBrowserFunc(cmd *cobra.Command) func(url string) error {
browser := env.Get(cmd.Context(), "BROWSER")
switch browser {
case "":
return browserpkg.OpenURL
return openURLSuppressingStderr
case "none":
return func(url string) error {
fmt.Fprintf(cmd.OutOrStdout(), "Please open %s in the browser to continue authentication\n", url)
fmt.Fprintf(cmd.OutOrStdout(), "Please complete authentication by opening this link in your browser:\n%s\n", url)
return nil
}
default:
Expand Down