Skip to content

Commit

Permalink
adjust error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Jul 16, 2020
1 parent 32ad2f6 commit 37613c3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions aws/data_source_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er
conn := meta.(*AWSClient).ecrconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

name := d.Get("name").(string)
params := &ecr.DescribeRepositoriesInput{
RepositoryNames: aws.StringSlice([]string{d.Get("name").(string)}),
RepositoryNames: aws.StringSlice([]string{name}),
}
log.Printf("[DEBUG] Reading ECR repository: %s", params)
out, err := conn.DescribeRepositories(params)
if err != nil {
return fmt.Errorf("error reading ECR repository: %s", err)
if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") {
return fmt.Errorf("ECR Repository (%s) not found", name)
}
return fmt.Errorf("error reading ECR repository: %w", err)
}

repository := out.Repositories[0]
Expand All @@ -61,11 +65,11 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er
tags, err := keyvaluetags.EcrListTags(conn, arn)

if err != nil {
return fmt.Errorf("error listing tags for ECR Repository (%s): %s", arn, err)
return fmt.Errorf("error listing tags for ECR Repository (%s): %w", arn, err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
return fmt.Errorf("error setting tags: %w", err)
}

return nil
Expand Down

0 comments on commit 37613c3

Please sign in to comment.