Skip to content

Commit

Permalink
fixup! codespace: Handle HTTP request retry interruption
Browse files Browse the repository at this point in the history
  • Loading branch information
azrsh committed Aug 17, 2023
1 parent 7aeb2b2 commit acd3566
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions internal/codespaces/codespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ type logger interface {
Printf(f string, v ...interface{})
}

type breakError struct{ err error }

func (b *breakError) Error() string {
return b.err.Error()
type TimeoutError struct {
message string
}

func (b *breakError) Unwrap() error {
return b.err
func (e *TimeoutError) Error() string {
return e.message
}

// ConnectToLiveshare waits for a Codespace to become running,
Expand All @@ -66,22 +64,22 @@ func ConnectToLiveshare(ctx context.Context, progress progressIndicator, session
var err error
codespace, err = apiClient.GetCodespace(ctx, codespace.Name, true)
if err != nil {
return backoff.Permanent(&breakError{err: fmt.Errorf("error getting codespace: %w", err)})
return backoff.Permanent(fmt.Errorf("error getting codespace: %w", err))
}

if connectionReady(codespace) {
return nil
}

return errors.New("codespace not ready yet")
return &TimeoutError{message: "codespace not ready yet"}
}, backoff.WithContext(expBackoff, ctx))
if err != nil {
var breakErr *breakError
if errors.As(err, &breakErr) {
return nil, errors.Unwrap(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
}
}

Expand Down

0 comments on commit acd3566

Please sign in to comment.