From bb42fa07aa7fd6044a875a82061ec3fe073a4962 Mon Sep 17 00:00:00 2001 From: azarashi Date: Fri, 18 Aug 2023 23:16:06 +0900 Subject: [PATCH] codespace: Handle HTTP request retry interruption (#7846) * codespace: Handle HTTP request retry interruption * codespace: Make the error message more detailed --- internal/codespaces/api/api.go | 2 +- internal/codespaces/codespaces.go | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/codespaces/api/api.go b/internal/codespaces/api/api.go index c55b92400ce..d6b21c304b0 100644 --- a/internal/codespaces/api/api.go +++ b/internal/codespaces/api/api.go @@ -1159,6 +1159,6 @@ func (a *API) withRetry(f func() (*http.Response, error)) (*http.Response, error if resp.StatusCode < 500 { return resp, nil } - return nil, errors.New("retry") + return nil, fmt.Errorf("received response with status code %d", resp.StatusCode) }, backoff.WithMaxRetries(bo, 3)) } diff --git a/internal/codespaces/codespaces.go b/internal/codespaces/codespaces.go index 9db12f01e1b..8834f0e6c28 100644 --- a/internal/codespaces/codespaces.go +++ b/internal/codespaces/codespaces.go @@ -35,6 +35,14 @@ type logger interface { Printf(f string, v ...interface{}) } +type TimeoutError struct { + message string +} + +func (e *TimeoutError) Error() string { + return e.message +} + // ConnectToLiveshare waits for a Codespace to become running, // and connects to it using a Live Share session. func ConnectToLiveshare(ctx context.Context, progress progressIndicator, sessionLogger logger, apiClient apiClient, codespace *api.Codespace) (*liveshare.Session, error) { @@ -63,15 +71,15 @@ func ConnectToLiveshare(ctx context.Context, progress progressIndicator, session return nil } - return errors.New("codespace not ready yet") + return &TimeoutError{message: "codespace not ready yet"} }, backoff.WithContext(expBackoff, ctx)) if err != nil { - var permErr *backoff.PermanentError - if errors.As(err, &permErr) { - return nil, err + var timeoutErr *TimeoutError + if errors.As(err, &timeoutErr) { + return nil, errors.New("timed out while waiting for the codespace to start") } - return nil, errors.New("timed out while waiting for the codespace to start") + return nil, err } }