diff options
author | Leandro Alves <leandroalves@yahooinc.com> | 2021-11-25 17:26:07 +0100 |
---|---|---|
committer | Leandro Alves <leandroalves@yahooinc.com> | 2021-11-25 17:26:07 +0100 |
commit | 69117dc281a44d6562afc340f58d1887ab5178d7 (patch) | |
tree | 7d1fe0a6c38fc482a5313e0141e183fa56fcb7ef /client | |
parent | 98d7e43c1d9a61f637c90becc4ec320e4a828a59 (diff) |
Change Spinner to return error
Diffstat (limited to 'client')
-rw-r--r-- | client/go/auth0/auth0.go | 4 | ||||
-rw-r--r-- | client/go/cmd/clone.go | 4 | ||||
-rw-r--r-- | client/go/util/spinner.go | 15 | ||||
-rw-r--r-- | client/go/vespa/deploy.go | 2 |
4 files changed, 11 insertions, 14 deletions
diff --git a/client/go/auth0/auth0.go b/client/go/auth0/auth0.go index f8f9bcb8f76..f94a933d96a 100644 --- a/client/go/auth0/auth0.go +++ b/client/go/auth0/auth0.go @@ -335,9 +335,9 @@ func RunLogin(ctx context.Context, a *Auth0, expired bool) (System, error) { } var res auth.Result - util.Spinner("Waiting for login to complete in browser ...", func() error { + err = util.Spinner("Waiting for login to complete in browser ...", func() error { res, err = a.Authenticator.Wait(ctx, state) - return nil + return err }) if err != nil { diff --git a/client/go/cmd/clone.go b/client/go/cmd/clone.go index e4bbd751f8a..6fe3c0d5a29 100644 --- a/client/go/cmd/clone.go +++ b/client/go/cmd/clone.go @@ -142,7 +142,7 @@ func getSampleAppsZip() *os.File { return f } - util.Spinner(color.Yellow("Downloading sample apps ...").String(), func() error { + err = util.Spinner(color.Yellow("Downloading sample apps ...").String(), func() error { request, err := http.NewRequest("GET", "https://github.com/vespa-engine/sample-apps/archive/refs/heads/master.zip", nil) if err != nil { fatalErr(err, "Invalid URL") @@ -162,7 +162,7 @@ func getSampleAppsZip() *os.File { fatalErr(err, "Could not write sample apps to file: ", f.Name()) return nil } - return nil + return err }) return f diff --git a/client/go/util/spinner.go b/client/go/util/spinner.go index 5e6522c3990..9f3c2cb4e44 100644 --- a/client/go/util/spinner.go +++ b/client/go/util/spinner.go @@ -3,7 +3,6 @@ package util import ( - "fmt" "os" "time" @@ -19,18 +18,18 @@ const ( var messages = os.Stderr -func Spinner(text string, fn func() error) { +func Spinner(text string, fn func() error) error { initialMsg := text + " " doneMsg := "\r" + initialMsg + spinnerTextDone + "\n" failMsg := "\r" + initialMsg + spinnerTextFailed + "\n" - loading(initialMsg, doneMsg, failMsg, fn) + return loading(initialMsg, doneMsg, failMsg, fn) } -func Waiting(fn func() error) { - loading("", "", "", fn) +func Waiting(fn func() error) error { + return loading("", "", "", fn) } -func loading(initialMsg, doneMsg, failMsg string, fn func() error) { +func loading(initialMsg, doneMsg, failMsg string, fn func() error) error { done := make(chan struct{}) errc := make(chan error) go func() { @@ -59,9 +58,7 @@ func loading(initialMsg, doneMsg, failMsg string, fn func() error) { errc <- err <-done - if err != nil { - fmt.Println(fmt.Errorf("an unexpected error occurred: %w", err)) - } + return err } func Error(e error, message string) error { diff --git a/client/go/vespa/deploy.go b/client/go/vespa/deploy.go index 7cd186e6b82..f2d4bf8c248 100644 --- a/client/go/vespa/deploy.go +++ b/client/go/vespa/deploy.go @@ -372,7 +372,7 @@ func uploadApplicationPackage(url *url.URL, opts DeploymentOpts) (int64, error) } var response *http.Response - util.Spinner("Uploading application package ...", func() error { + err = util.Spinner("Uploading application package ...", func() error { response, err = util.HttpDo(request, time.Minute*10, serviceDescription) return err }) |