mirror of
https://github.com/int128/kubelogin.git
synced 2026-02-14 16:39:51 +00:00
Improve error message if cannot open browser (#230)
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/google/wire"
|
||||
"github.com/pkg/browser"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination mock_browser/mock_browser.go github.com/int128/kubelogin/pkg/adaptors/browser Interface
|
||||
@@ -31,8 +30,5 @@ type Browser struct{}
|
||||
|
||||
// Open opens the default browser.
|
||||
func (*Browser) Open(url string) error {
|
||||
if err := browser.OpenURL(url); err != nil {
|
||||
return xerrors.Errorf("could not open the browser: %w", err)
|
||||
}
|
||||
return nil
|
||||
return browser.OpenURL(url)
|
||||
}
|
||||
|
||||
@@ -46,12 +46,15 @@ func (u *AuthCode) Do(ctx context.Context, o *AuthCodeOption, client oidcclient.
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
u.Logger.Printf("Open %s for authentication", url)
|
||||
if o.SkipOpenBrowser {
|
||||
u.Logger.Printf("Please visit the following URL in your browser: %s", url)
|
||||
return nil
|
||||
}
|
||||
if err := u.Browser.Open(url); err != nil {
|
||||
u.Logger.V(1).Infof("could not open the browser: %s", err)
|
||||
u.Logger.Printf(`error: could not open the browser: %s
|
||||
|
||||
Please visit the following URL in your browser manually: %s`, err, url)
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user