Skip to content

Commit

Permalink
Don't parse url errors
Browse files Browse the repository at this point in the history
  • Loading branch information
atburke committed Jun 5, 2024
1 parent 6ba6b9a commit a420d8b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
16 changes: 0 additions & 16 deletions lib/cloud/gcp/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import (
"fmt"
"io"
"net"
"net/url"
"regexp"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -58,10 +55,6 @@ const sshUser = "teleport"
// sshDefaultTimeout is the default timeout for dialing an instance.
const sshDefaultTimeout = 10 * time.Second

// urlErrorCodePattern is a regex for attempting to extract an HTTP error
// code from a *url.Error.
var urlErrorCodePattern = regexp.MustCompile(`\b[2-5]\d{2}\b`)

// convertAPIError converts an error from the GCP API into a trace error.
func convertAPIError(err error) error {
var googleError *googleapi.Error
Expand All @@ -76,15 +69,6 @@ func convertAPIError(err error) error {
return trail.FromGRPC(apiError)
}
}
var urlError *url.Error
if errors.As(err, &urlError) {
if codeStr := urlErrorCodePattern.FindString(urlError.Error()); codeStr != "" {
code, err := strconv.Atoi(codeStr)
if err == nil {
return trace.ReadError(code, []byte(urlError.Error()))
}
}
}
return err
}

Expand Down
10 changes: 0 additions & 10 deletions lib/cloud/gcp/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ package gcp
import (
"bytes"
"context"
"fmt"
"net"
"net/http"
"net/url"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -72,14 +70,6 @@ func TestConvertAPIError(t *testing.T) {
name: "api grpc error",
err: fromError(t, status.Error(codes.PermissionDenied, "abcd1234")),
},
{
name: "url error",
err: &url.Error{
Op: http.MethodGet,
URL: "https://example.com",
Err: fmt.Errorf("wrong code 99, wrong code 2007, wrong code 678, right code 403, wrong code 401 abcd1234"),
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) {
Clock: cfg.Clock,
})
if err != nil {
cfg.Logger.ErrorContext(supervisor.ExitContext(), "Error creating cloud label importer.", "error", err)
cfg.Logger.ErrorContext(supervisor.ExitContext(), "Cloud labels will not be imported", "error", err)
}
}

Expand Down

0 comments on commit a420d8b

Please sign in to comment.