Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return better errors for unavailable error codes #2336

Merged
merged 7 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion private/buf/bufcli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import (
"context"
"crypto/tls"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -174,7 +175,9 @@
if dnsError := (&net.DNSError{}); errors.As(err, &dnsError) && dnsError.IsNotFound {
return fmt.Errorf(`%s Are you sure "%s" is a valid remote address?`, msg, dnsError.Name)
}

if tlsErr := (&tls.CertificateVerificationError{}); errors.As(err, &tlsErr) {

Check failure on line 178 in private/buf/bufcli/errors.go

View workflow job for this annotation

GitHub Actions / test-previous

undefined: tls.CertificateVerificationError
return tlsErr
pkwarren marked this conversation as resolved.
Show resolved Hide resolved
}
return errors.New(msg)
}
return fmt.Errorf("Failure: %s", connectErr.Message())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func inner(
authnService := connectclient.Make(clientConfig, remote, registryv1alpha1connect.NewAuthnServiceClient)
resp, err := authnService.GetCurrentUser(ctx, connect.NewRequest(&registryv1alpha1.GetCurrentUserRequest{}))
if err != nil {
if connectErr := new(connect.Error); errors.As(err, &connectErr) && connectErr.Code() == connect.CodeUnavailable {
return connectErr
}
// We don't want to use the default error from wrapError here if the error
// an unauthenticated error.
return errors.New("invalid token provided")
Comment on lines +191 to 196
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were going to invoke wrapError here.

Expand Down