forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 5
/
errors.go
101 lines (84 loc) · 3.1 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package aws
import (
"fmt"
)
// IpForEc2InstanceNotFound is an error that occurs when the IP for an EC2 instance is not found.
type IpForEc2InstanceNotFound struct {
InstanceId string
AwsRegion string
Type string
}
func (err IpForEc2InstanceNotFound) Error() string {
return fmt.Sprintf("Could not find a %s IP address for EC2 Instance %s in %s", err.Type, err.InstanceId, err.AwsRegion)
}
// HostnameForEc2InstanceNotFound is an error that occurs when the IP for an EC2 instance is not found.
type HostnameForEc2InstanceNotFound struct {
InstanceId string
AwsRegion string
Type string
}
func (err HostnameForEc2InstanceNotFound) Error() string {
return fmt.Sprintf("Could not find a %s hostname for EC2 Instance %s in %s", err.Type, err.InstanceId, err.AwsRegion)
}
// NotFoundError is returned when an expected object is not found
type NotFoundError struct {
objectType string
objectID string
region string
}
func (err NotFoundError) Error() string {
return fmt.Sprintf("Object of type %s with id %s not found in region %s", err.objectType, err.objectID, err.region)
}
func NewNotFoundError(objectType string, objectID string, region string) NotFoundError {
return NotFoundError{objectType, objectID, region}
}
// AsgCapacityNotMetError is returned when the ASG capacity is not yet at the desired capacity.
type AsgCapacityNotMetError struct {
asgName string
desiredCapacity int64
currentCapacity int64
}
func (err AsgCapacityNotMetError) Error() string {
return fmt.Sprintf(
"ASG %s not yet at desired capacity %d (current %d)",
err.asgName,
err.desiredCapacity,
err.currentCapacity,
)
}
func NewAsgCapacityNotMetError(asgName string, desiredCapacity int64, currentCapacity int64) AsgCapacityNotMetError {
return AsgCapacityNotMetError{asgName, desiredCapacity, currentCapacity}
}
// BucketVersioningNotEnabledError is returned when an S3 bucket that should have versioning does not have it applied
type BucketVersioningNotEnabledError struct {
s3BucketName string
awsRegion string
versioningStatus string
}
func (err BucketVersioningNotEnabledError) Error() string {
return fmt.Sprintf(
"Versioning status for bucket %s in the %s region is %s",
err.s3BucketName,
err.awsRegion,
err.versioningStatus,
)
}
func NewBucketVersioningNotEnabledError(s3BucketName string, awsRegion string, versioningStatus string) BucketVersioningNotEnabledError {
return BucketVersioningNotEnabledError{s3BucketName: s3BucketName, awsRegion: awsRegion, versioningStatus: versioningStatus}
}
// NoBucketPolicyError is returned when an S3 bucket that should have a policy applied does not
type NoBucketPolicyError struct {
s3BucketName string
awsRegion string
bucketPolicy string
}
func (err NoBucketPolicyError) Error() string {
return fmt.Sprintf(
"The policy for bucket %s in the %s region does not have a policy attached.",
err.s3BucketName,
err.awsRegion,
)
}
func NewNoBucketPolicyError(s3BucketName string, awsRegion string, bucketPolicy string) NoBucketPolicyError {
return NoBucketPolicyError{s3BucketName: s3BucketName, awsRegion: awsRegion, bucketPolicy: bucketPolicy}
}