aws: errors with context

When faced with errors from cloud providers (like "Throttling: Rate exceeded"), it's not always easy to find what operation caused the failure, and what action was aborted, if any,

Let's make it easier to identify an error source (and affected object when possible) by providing more context (and by using easy to find error messages).
This commit is contained in:
Benjamin Pineau 2020-08-04 08:00:21 +02:00
parent 3a61439cd1
commit b64e3ac832
2 changed files with 11 additions and 10 deletions

View File

@ -1,5 +1,6 @@
## Unreleased ## Unreleased
- Improve errors context for AWS provider
## v0.7.3 - 2020-08-05 ## v0.7.3 - 2020-08-05

View File

@ -166,7 +166,7 @@ func NewAWSProvider(awsConfig AWSConfig) (*AWSProvider, error) {
SharedConfigState: session.SharedConfigEnable, SharedConfigState: session.SharedConfigEnable,
}) })
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to instantiate AWS session: %w", err)
} }
if awsConfig.AssumeRole != "" { if awsConfig.AssumeRole != "" {
@ -229,10 +229,10 @@ func (p *AWSProvider) Zones(ctx context.Context) (map[string]*route53.HostedZone
err := p.client.ListHostedZonesPagesWithContext(ctx, &route53.ListHostedZonesInput{}, f) err := p.client.ListHostedZonesPagesWithContext(ctx, &route53.ListHostedZonesInput{}, f)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to list hosted zones: %w", err)
} }
if tagErr != nil { if tagErr != nil {
return nil, tagErr return nil, fmt.Errorf("failed to list zones tags: %w", tagErr)
} }
for _, zone := range zones { for _, zone := range zones {
@ -255,7 +255,7 @@ func wildcardUnescape(s string) string {
func (p *AWSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoint, _ error) { func (p *AWSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoint, _ error) {
zones, err := p.Zones(ctx) zones, err := p.Zones(ctx)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("records retrieval failed: %w", err)
} }
return p.records(ctx, zones) return p.records(ctx, zones)
@ -339,7 +339,7 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*route53.Hos
} }
if err := p.client.ListResourceRecordSetsPagesWithContext(ctx, params, f); err != nil { if err := p.client.ListResourceRecordSetsPagesWithContext(ctx, params, f); err != nil {
return nil, err return nil, fmt.Errorf("failed to list resource records sets for zone %s: %w", *z.Id, err)
} }
} }
@ -364,12 +364,12 @@ func (p *AWSProvider) DeleteRecords(ctx context.Context, endpoints []*endpoint.E
func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []*endpoint.Endpoint) error { func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []*endpoint.Endpoint) error {
zones, err := p.Zones(ctx) zones, err := p.Zones(ctx)
if err != nil { if err != nil {
return err return fmt.Errorf("failed to list zones, aborting %s doRecords action: %w", action, err)
} }
records, err := p.records(ctx, zones) records, err := p.records(ctx, zones)
if err != nil { if err != nil {
log.Errorf("getting records failed: %v", err) log.Errorf("failed to list records while preparing %s doRecords action: %s", action, err)
} }
return p.submitChanges(ctx, p.newChanges(action, endpoints, records, zones), zones) return p.submitChanges(ctx, p.newChanges(action, endpoints, records, zones), zones)
} }
@ -378,7 +378,7 @@ func (p *AWSProvider) doRecords(ctx context.Context, action string, endpoints []
func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error { func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
zones, err := p.Zones(ctx) zones, err := p.Zones(ctx)
if err != nil { if err != nil {
return err return fmt.Errorf("failed to list zones, not applying changes: %w", err)
} }
records, ok := ctx.Value(provider.RecordsContextKey).([]*endpoint.Endpoint) records, ok := ctx.Value(provider.RecordsContextKey).([]*endpoint.Endpoint)
@ -386,7 +386,7 @@ func (p *AWSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e
var err error var err error
records, err = p.records(ctx, zones) records, err = p.records(ctx, zones)
if err != nil { if err != nil {
log.Errorf("getting records failed: %v", err) log.Errorf("failed to get records while preparing to applying changes: %s", err)
} }
} }
@ -581,7 +581,7 @@ func (p *AWSProvider) tagsForZone(ctx context.Context, zoneID string) (map[strin
ResourceId: aws.String(zoneID), ResourceId: aws.String(zoneID),
}) })
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to list tags for zone %s: %w", zoneID, err)
} }
tagMap := map[string]string{} tagMap := map[string]string{}
for _, tag := range response.ResourceTagSet.Tags { for _, tag := range response.ResourceTagSet.Tags {