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

aws: Cleanup exported concrete error types, only export error codes #510

Merged
merged 5 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Breaking Change
* `aws/external`: Removes several export constants and types ([#508](https://github.com/aws/aws-sdk-go-v2/pull/508))
* No longer exports AWS environment constants used by the external environment configuration loader
* `DefaultSharedConfigProfile` is now defined an exported constant
* `aws`: `ErrMissingRegion`, `ErrMissingEndpoint`, `ErrStaticCredentialsEmpty` are now concrete error types ([#510](https://github.com/aws/aws-sdk-go-v2/pull/510))

Services
---
Expand Down
4 changes: 2 additions & 2 deletions aws/defaults/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ var RetryableCheckHandler = aws.NamedHandler{
// region is not valid.
var ValidateEndpointHandler = aws.NamedHandler{Name: "core.ValidateEndpointHandler", Fn: func(r *aws.Request) {
if r.Endpoint.SigningRegion == "" && r.Config.Region == "" {
r.Error = aws.ErrMissingRegion
r.Error = &aws.MissingRegionError{}
} else if len(r.Endpoint.URL) == 0 {
r.Error = aws.ErrMissingEndpoint
r.Error = &aws.MissingEndpointError{}
}
}}

Expand Down
5 changes: 3 additions & 2 deletions aws/defaults/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ func TestValidateEndpointHandlerErrorRegion(t *testing.T) {
if err == nil {
t.Errorf("expect error, got none")
}
if e, a := aws.ErrMissingRegion, err; e != a {
t.Errorf("expect %v to be %v", e, a)
var expected *aws.MissingRegionError
if !errors.As(err, &expected) {
t.Fatalf("expected %T, got %T", expected, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion aws/ec2metadata/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,6 @@ func unmarshalError(r *aws.Request) {

func validateEndpointHandler(r *aws.Request) {
if len(r.Endpoint.URL) == 0 {
r.Error = aws.ErrMissingEndpoint
r.Error = &aws.MissingEndpointError{}
}
}
2 changes: 1 addition & 1 deletion aws/endpointcreds/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (p *Provider) getCredentials() (*getCredentialsOutput, error) {

func validateEndpointHandler(r *aws.Request) {
if len(r.Endpoint.URL) == 0 {
r.Error = aws.ErrMissingEndpoint
r.Error = &aws.MissingEndpointError{}
}
}

Expand Down
24 changes: 11 additions & 13 deletions aws/errors.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package aws

import "github.com/aws/aws-sdk-go-v2/aws/awserr"
// MissingRegionError is an error that is returned if region configuration is not found.
type MissingRegionError struct{}

var (
// ErrMissingRegion is an error that is returned if region configuration is
// not found.
//
// @readonly
ErrMissingRegion = awserr.New("MissingRegion", "could not find region configuration", nil)
func (*MissingRegionError) Error() string {
return "could not find region configuration"
}

// ErrMissingEndpoint is an error that is returned if an endpoint cannot be
// resolved for a service.
//
// @readonly
ErrMissingEndpoint = awserr.New("MissingEndpoint", "'Endpoint' configuration is required for this service", nil)
)
// MissingEndpointError is an error that is returned if an endpoint cannot be resolved for a service.
type MissingEndpointError struct{}

func (*MissingEndpointError) Error() string {
return "'Endpoint' configuration is required for this service"
}
20 changes: 11 additions & 9 deletions aws/static_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package aws

import (
"context"
)

"github.com/aws/aws-sdk-go-v2/aws/awserr"
const (
// StaticCredentialsProviderName provides a name of Static provider
StaticCredentialsProviderName = "StaticCredentialsProvider"
)

// StaticCredentialsProviderName provides a name of Static provider
const StaticCredentialsProviderName = "StaticCredentialsProvider"
// StaticCredentialsEmptyError is emitted when static credentials are empty.
type StaticCredentialsEmptyError struct{}

var (
// ErrStaticCredentialsEmpty is emitted when static credentials are empty.
ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil)
)
func (*StaticCredentialsEmptyError) Error() string {
return "static credentials are empty"
}

// A StaticCredentialsProvider is a set of credentials which are set programmatically,
// and will never expire.
Expand All @@ -33,10 +35,10 @@ func NewStaticCredentialsProvider(key, secret, session string) StaticCredentials
}

// Retrieve returns the credentials or error if the credentials are invalid.
func (s StaticCredentialsProvider) Retrieve(ctx context.Context) (Credentials, error) {
func (s StaticCredentialsProvider) Retrieve(_ context.Context) (Credentials, error) {
v := s.Value
if v.AccessKeyID == "" || v.SecretAccessKey == "" {
return Credentials{Source: StaticCredentialsProviderName}, ErrStaticCredentialsEmpty
return Credentials{Source: StaticCredentialsProviderName}, &StaticCredentialsEmptyError{}
}

if len(v.Source) == 0 {
Expand Down
11 changes: 7 additions & 4 deletions service/cloudsearchdomain/customizations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cloudsearchdomain_test

import (
"errors"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -25,8 +26,9 @@ func TestRequireEndpointIfRegionProvided(t *testing.T) {
if err == nil {
t.Errorf("expect error, got none")
}
if e, a := aws.ErrMissingEndpoint, err; e != a {
t.Errorf("expect %v, got %v", e, a)
var expected *aws.MissingEndpointError
if !errors.As(err, &expected) {
t.Fatalf("expected %T, got %T", expected, err)
}
}

Expand All @@ -45,8 +47,9 @@ func TestRequireEndpointIfNoRegionProvided(t *testing.T) {
if err == nil {
t.Errorf("expect error, got none")
}
if e, a := aws.ErrMissingEndpoint, err; e != a {
t.Errorf("expect %v, got %v", e, a)
var expected *aws.MissingEndpointError
if !errors.As(err, &expected) {
t.Fatalf("expected %T, got %T", expected, err)
}
}

Expand Down
11 changes: 7 additions & 4 deletions service/iotdataplane/customizations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iotdataplane_test

import (
"errors"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -24,8 +25,9 @@ func TestRequireEndpointIfRegionProvided(t *testing.T) {
if err == nil {
t.Errorf("expect error, got none")
}
if e, a := aws.ErrMissingEndpoint, err; e != a {
t.Errorf("expect %v, got %v", e, a)
var expected *aws.MissingEndpointError
if !errors.As(err, &expected) {
t.Fatalf("expected %T, got %T", expected, err)
}
}

Expand All @@ -45,8 +47,9 @@ func TestRequireEndpointIfNoRegionProvided(t *testing.T) {
if err == nil {
t.Errorf("expect error, got none")
}
if e, a := aws.ErrMissingEndpoint, err; e != a {
t.Errorf("expect %v, got %v", e, a)
var expected *aws.MissingEndpointError
if !errors.As(err, &expected) {
t.Fatalf("expected %T, got %T", expected, err)
}
}

Expand Down