diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/aws/aws-sdk-go/aws/awserr | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/aws/awserr')
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/aws/awserr/error.go | 145 | ||||
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go | 194 |
2 files changed, 339 insertions, 0 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/aws/awserr/error.go b/vendor/github.com/aws/aws-sdk-go/aws/awserr/error.go new file mode 100644 index 0000000..56fdfc2 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/aws/awserr/error.go | |||
@@ -0,0 +1,145 @@ | |||
1 | // Package awserr represents API error interface accessors for the SDK. | ||
2 | package awserr | ||
3 | |||
4 | // An Error wraps lower level errors with code, message and an original error. | ||
5 | // The underlying concrete error type may also satisfy other interfaces which | ||
6 | // can be to used to obtain more specific information about the error. | ||
7 | // | ||
8 | // Calling Error() or String() will always include the full information about | ||
9 | // an error based on its underlying type. | ||
10 | // | ||
11 | // Example: | ||
12 | // | ||
13 | // output, err := s3manage.Upload(svc, input, opts) | ||
14 | // if err != nil { | ||
15 | // if awsErr, ok := err.(awserr.Error); ok { | ||
16 | // // Get error details | ||
17 | // log.Println("Error:", awsErr.Code(), awsErr.Message()) | ||
18 | // | ||
19 | // // Prints out full error message, including original error if there was one. | ||
20 | // log.Println("Error:", awsErr.Error()) | ||
21 | // | ||
22 | // // Get original error | ||
23 | // if origErr := awsErr.OrigErr(); origErr != nil { | ||
24 | // // operate on original error. | ||
25 | // } | ||
26 | // } else { | ||
27 | // fmt.Println(err.Error()) | ||
28 | // } | ||
29 | // } | ||
30 | // | ||
31 | type Error interface { | ||
32 | // Satisfy the generic error interface. | ||
33 | error | ||
34 | |||
35 | // Returns the short phrase depicting the classification of the error. | ||
36 | Code() string | ||
37 | |||
38 | // Returns the error details message. | ||
39 | Message() string | ||
40 | |||
41 | // Returns the original error if one was set. Nil is returned if not set. | ||
42 | OrigErr() error | ||
43 | } | ||
44 | |||
45 | // BatchError is a batch of errors which also wraps lower level errors with | ||
46 | // code, message, and original errors. Calling Error() will include all errors | ||
47 | // that occurred in the batch. | ||
48 | // | ||
49 | // Deprecated: Replaced with BatchedErrors. Only defined for backwards | ||
50 | // compatibility. | ||
51 | type BatchError interface { | ||
52 | // Satisfy the generic error interface. | ||
53 | error | ||
54 | |||
55 | // Returns the short phrase depicting the classification of the error. | ||
56 | Code() string | ||
57 | |||
58 | // Returns the error details message. | ||
59 | Message() string | ||
60 | |||
61 | // Returns the original error if one was set. Nil is returned if not set. | ||
62 | OrigErrs() []error | ||
63 | } | ||
64 | |||
65 | // BatchedErrors is a batch of errors which also wraps lower level errors with | ||
66 | // code, message, and original errors. Calling Error() will include all errors | ||
67 | // that occurred in the batch. | ||
68 | // | ||
69 | // Replaces BatchError | ||
70 | type BatchedErrors interface { | ||
71 | // Satisfy the base Error interface. | ||
72 | Error | ||
73 | |||
74 | // Returns the original error if one was set. Nil is returned if not set. | ||
75 | OrigErrs() []error | ||
76 | } | ||
77 | |||
78 | // New returns an Error object described by the code, message, and origErr. | ||
79 | // | ||
80 | // If origErr satisfies the Error interface it will not be wrapped within a new | ||
81 | // Error object and will instead be returned. | ||
82 | func New(code, message string, origErr error) Error { | ||
83 | var errs []error | ||
84 | if origErr != nil { | ||
85 | errs = append(errs, origErr) | ||
86 | } | ||
87 | return newBaseError(code, message, errs) | ||
88 | } | ||
89 | |||
90 | // NewBatchError returns an BatchedErrors with a collection of errors as an | ||
91 | // array of errors. | ||
92 | func NewBatchError(code, message string, errs []error) BatchedErrors { | ||
93 | return newBaseError(code, message, errs) | ||
94 | } | ||
95 | |||
96 | // A RequestFailure is an interface to extract request failure information from | ||
97 | // an Error such as the request ID of the failed request returned by a service. | ||
98 | // RequestFailures may not always have a requestID value if the request failed | ||
99 | // prior to reaching the service such as a connection error. | ||
100 | // | ||
101 | // Example: | ||
102 | // | ||
103 | // output, err := s3manage.Upload(svc, input, opts) | ||
104 | // if err != nil { | ||
105 | // if reqerr, ok := err.(RequestFailure); ok { | ||
106 | // log.Println("Request failed", reqerr.Code(), reqerr.Message(), reqerr.RequestID()) | ||
107 | // } else { | ||
108 | // log.Println("Error:", err.Error()) | ||
109 | // } | ||
110 | // } | ||
111 | // | ||
112 | // Combined with awserr.Error: | ||
113 | // | ||
114 | // output, err := s3manage.Upload(svc, input, opts) | ||
115 | // if err != nil { | ||
116 | // if awsErr, ok := err.(awserr.Error); ok { | ||
117 | // // Generic AWS Error with Code, Message, and original error (if any) | ||
118 | // fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) | ||
119 | // | ||
120 | // if reqErr, ok := err.(awserr.RequestFailure); ok { | ||
121 | // // A service error occurred | ||
122 | // fmt.Println(reqErr.StatusCode(), reqErr.RequestID()) | ||
123 | // } | ||
124 | // } else { | ||
125 | // fmt.Println(err.Error()) | ||
126 | // } | ||
127 | // } | ||
128 | // | ||
129 | type RequestFailure interface { | ||
130 | Error | ||
131 | |||
132 | // The status code of the HTTP response. | ||
133 | StatusCode() int | ||
134 | |||
135 | // The request ID returned by the service for a request failure. This will | ||
136 | // be empty if no request ID is available such as the request failed due | ||
137 | // to a connection error. | ||
138 | RequestID() string | ||
139 | } | ||
140 | |||
141 | // NewRequestFailure returns a new request error wrapper for the given Error | ||
142 | // provided. | ||
143 | func NewRequestFailure(err Error, statusCode int, reqID string) RequestFailure { | ||
144 | return newRequestError(err, statusCode, reqID) | ||
145 | } | ||
diff --git a/vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go b/vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go new file mode 100644 index 0000000..0202a00 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go | |||
@@ -0,0 +1,194 @@ | |||
1 | package awserr | ||
2 | |||
3 | import "fmt" | ||
4 | |||
5 | // SprintError returns a string of the formatted error code. | ||
6 | // | ||
7 | // Both extra and origErr are optional. If they are included their lines | ||
8 | // will be added, but if they are not included their lines will be ignored. | ||
9 | func SprintError(code, message, extra string, origErr error) string { | ||
10 | msg := fmt.Sprintf("%s: %s", code, message) | ||
11 | if extra != "" { | ||
12 | msg = fmt.Sprintf("%s\n\t%s", msg, extra) | ||
13 | } | ||
14 | if origErr != nil { | ||
15 | msg = fmt.Sprintf("%s\ncaused by: %s", msg, origErr.Error()) | ||
16 | } | ||
17 | return msg | ||
18 | } | ||
19 | |||
20 | // A baseError wraps the code and message which defines an error. It also | ||
21 | // can be used to wrap an original error object. | ||
22 | // | ||
23 | // Should be used as the root for errors satisfying the awserr.Error. Also | ||
24 | // for any error which does not fit into a specific error wrapper type. | ||
25 | type baseError struct { | ||
26 | // Classification of error | ||
27 | code string | ||
28 | |||
29 | // Detailed information about error | ||
30 | message string | ||
31 | |||
32 | // Optional original error this error is based off of. Allows building | ||
33 | // chained errors. | ||
34 | errs []error | ||
35 | } | ||
36 | |||
37 | // newBaseError returns an error object for the code, message, and errors. | ||
38 | // | ||
39 | // code is a short no whitespace phrase depicting the classification of | ||
40 | // the error that is being created. | ||
41 | // | ||
42 | // message is the free flow string containing detailed information about the | ||
43 | // error. | ||
44 | // | ||
45 | // origErrs is the error objects which will be nested under the new errors to | ||
46 | // be returned. | ||
47 | func newBaseError(code, message string, origErrs []error) *baseError { | ||
48 | b := &baseError{ | ||
49 | code: code, | ||
50 | message: message, | ||
51 | errs: origErrs, | ||
52 | } | ||
53 | |||
54 | return b | ||
55 | } | ||
56 | |||
57 | // Error returns the string representation of the error. | ||
58 | // | ||
59 | // See ErrorWithExtra for formatting. | ||
60 | // | ||
61 | // Satisfies the error interface. | ||
62 | func (b baseError) Error() string { | ||
63 | size := len(b.errs) | ||
64 | if size > 0 { | ||
65 | return SprintError(b.code, b.message, "", errorList(b.errs)) | ||
66 | } | ||
67 | |||
68 | return SprintError(b.code, b.message, "", nil) | ||
69 | } | ||
70 | |||
71 | // String returns the string representation of the error. | ||
72 | // Alias for Error to satisfy the stringer interface. | ||
73 | func (b baseError) String() string { | ||
74 | return b.Error() | ||
75 | } | ||
76 | |||
77 | // Code returns the short phrase depicting the classification of the error. | ||
78 | func (b baseError) Code() string { | ||
79 | return b.code | ||
80 | } | ||
81 | |||
82 | // Message returns the error details message. | ||
83 | func (b baseError) Message() string { | ||
84 | return b.message | ||
85 | } | ||
86 | |||
87 | // OrigErr returns the original error if one was set. Nil is returned if no | ||
88 | // error was set. This only returns the first element in the list. If the full | ||
89 | // list is needed, use BatchedErrors. | ||
90 | func (b baseError) OrigErr() error { | ||
91 | switch len(b.errs) { | ||
92 | case 0: | ||
93 | return nil | ||
94 | case 1: | ||
95 | return b.errs[0] | ||
96 | default: | ||
97 | if err, ok := b.errs[0].(Error); ok { | ||
98 | return NewBatchError(err.Code(), err.Message(), b.errs[1:]) | ||
99 | } | ||
100 | return NewBatchError("BatchedErrors", | ||
101 | "multiple errors occurred", b.errs) | ||
102 | } | ||
103 | } | ||
104 | |||
105 | // OrigErrs returns the original errors if one was set. An empty slice is | ||
106 | // returned if no error was set. | ||
107 | func (b baseError) OrigErrs() []error { | ||
108 | return b.errs | ||
109 | } | ||
110 | |||
111 | // So that the Error interface type can be included as an anonymous field | ||
112 | // in the requestError struct and not conflict with the error.Error() method. | ||
113 | type awsError Error | ||
114 | |||
115 | // A requestError wraps a request or service error. | ||
116 | // | ||
117 | // Composed of baseError for code, message, and original error. | ||
118 | type requestError struct { | ||
119 | awsError | ||
120 | statusCode int | ||
121 | requestID string | ||
122 | } | ||
123 | |||
124 | // newRequestError returns a wrapped error with additional information for | ||
125 | // request status code, and service requestID. | ||
126 | // | ||
127 | // Should be used to wrap all request which involve service requests. Even if | ||
128 | // the request failed without a service response, but had an HTTP status code | ||
129 | // that may be meaningful. | ||
130 | // | ||
131 | // Also wraps original errors via the baseError. | ||
132 | func newRequestError(err Error, statusCode int, requestID string) *requestError { | ||
133 | return &requestError{ | ||
134 | awsError: err, | ||
135 | statusCode: statusCode, | ||
136 | requestID: requestID, | ||
137 | } | ||
138 | } | ||
139 | |||
140 | // Error returns the string representation of the error. | ||
141 | // Satisfies the error interface. | ||
142 | func (r requestError) Error() string { | ||
143 | extra := fmt.Sprintf("status code: %d, request id: %s", | ||
144 | r.statusCode, r.requestID) | ||
145 | return SprintError(r.Code(), r.Message(), extra, r.OrigErr()) | ||
146 | } | ||
147 | |||
148 | // String returns the string representation of the error. | ||
149 | // Alias for Error to satisfy the stringer interface. | ||
150 | func (r requestError) String() string { | ||
151 | return r.Error() | ||
152 | } | ||
153 | |||
154 | // StatusCode returns the wrapped status code for the error | ||
155 | func (r requestError) StatusCode() int { | ||
156 | return r.statusCode | ||
157 | } | ||
158 | |||
159 | // RequestID returns the wrapped requestID | ||
160 | func (r requestError) RequestID() string { | ||
161 | return r.requestID | ||
162 | } | ||
163 | |||
164 | // OrigErrs returns the original errors if one was set. An empty slice is | ||
165 | // returned if no error was set. | ||
166 | func (r requestError) OrigErrs() []error { | ||
167 | if b, ok := r.awsError.(BatchedErrors); ok { | ||
168 | return b.OrigErrs() | ||
169 | } | ||
170 | return []error{r.OrigErr()} | ||
171 | } | ||
172 | |||
173 | // An error list that satisfies the golang interface | ||
174 | type errorList []error | ||
175 | |||
176 | // Error returns the string representation of the error. | ||
177 | // | ||
178 | // Satisfies the error interface. | ||
179 | func (e errorList) Error() string { | ||
180 | msg := "" | ||
181 | // How do we want to handle the array size being zero | ||
182 | if size := len(e); size > 0 { | ||
183 | for i := 0; i < size; i++ { | ||
184 | msg += fmt.Sprintf("%s", e[i].Error()) | ||
185 | // We check the next index to see if it is within the slice. | ||
186 | // If it is, then we append a newline. We do this, because unit tests | ||
187 | // could be broken with the additional '\n' | ||
188 | if i+1 < size { | ||
189 | msg += "\n" | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | return msg | ||
194 | } | ||