|
6 | 6 | "bufio" |
7 | 7 | "context" |
8 | 8 | "fmt" |
| 9 | + "io" |
9 | 10 | "os" |
10 | 11 | "strings" |
11 | 12 |
|
@@ -48,17 +49,32 @@ func (l *loginProvider) Login(ctx context.Context) (string, error) { |
48 | 49 |
|
49 | 50 | // Read Y/n response |
50 | 51 | reader := bufio.NewReader(os.Stdin) |
51 | | - response, _ := reader.ReadString('\n') |
| 52 | + response, err := reader.ReadString('\n') |
| 53 | + if err != nil { |
| 54 | + if err == io.EOF { |
| 55 | + // Non-interactive shell, treat as empty (yes) |
| 56 | + response = "" |
| 57 | + } else { |
| 58 | + output.EmitLog(l.sink, fmt.Sprintf("Failed to read input: %v (non-interactive shell?)", err)) |
| 59 | + return "", fmt.Errorf("failed to read input: %w", err) |
| 60 | + } |
| 61 | + } |
52 | 62 | response = strings.TrimSpace(strings.ToLower(response)) |
53 | 63 |
|
54 | 64 | // Open browser if yes (default to yes on empty input) |
55 | 65 | if response == "" || response == "y" || response == "yes" { |
56 | | - _ = browser.OpenURL(authURL) |
| 66 | + if err := browser.OpenURL(authURL); err != nil { |
| 67 | + output.EmitLog(l.sink, fmt.Sprintf("Warning: Failed to open browser: %v", err)) |
| 68 | + } |
57 | 69 | } |
58 | 70 |
|
59 | 71 | // Wait for ENTER to check status |
60 | 72 | output.EmitLog(l.sink, "Waiting for authentication (Press [ENTER] when complete)") |
61 | | - _, _ = reader.ReadString('\n') |
| 73 | + _, err = reader.ReadString('\n') |
| 74 | + if err != nil && err != io.EOF { |
| 75 | + output.EmitLog(l.sink, fmt.Sprintf("Failed to read input: %v", err)) |
| 76 | + return "", fmt.Errorf("failed to read input: %w", err) |
| 77 | + } |
62 | 78 |
|
63 | 79 | // Check authentication status once |
64 | 80 | return l.completeAuth(ctx, authReq) |
|
0 commit comments