Improve error message if cannot open browser (#230)

This commit is contained in:
Hidetake Iwata
2020-02-11 15:50:10 +09:00
committed by GitHub
parent 9018cd65c5
commit 2fa306c348
2 changed files with 6 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -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():