Skip to content

Commit b577016

Browse files
authored
aws: rename CanceledErrorCode to ErrCodeRequestCanceled (#131)
Renames aws.CanceledErrorCode to be more consistent to the SDK's existing error code constants. This is a breaking change and any useages of the existing `aws.CanceledErrorCode` should be replaced with `aws.ErrCodeRequestCanceled` Use the following command to rename your code's usage: ``` gofmt -r 'aws.CanceledErrorCode -> aws.ErrCodeRequestCanceled' -l -w . ```
1 parent 6224776 commit b577016

File tree

12 files changed

+17
-17
lines changed

12 files changed

+17
-17
lines changed

aws/defaults/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func handleSendError(r *aws.Request, err error) {
179179
ctx := r.Context()
180180
select {
181181
case <-ctx.Done():
182-
r.Error = awserr.New(aws.CanceledErrorCode,
182+
r.Error = awserr.New(aws.ErrCodeRequestCanceled,
183183
"request context canceled", ctx.Err())
184184
r.Retryable = aws.Bool(false)
185185
default:
@@ -207,7 +207,7 @@ var AfterRetryHandler = aws.NamedHandler{Name: "core.AfterRetryHandler", Fn: fun
207207
r.RetryDelay = r.RetryRules(r)
208208

209209
if err := sdk.SleepWithContext(r.Context(), r.RetryDelay); err != nil {
210-
r.Error = awserr.New(aws.CanceledErrorCode,
210+
r.Error = awserr.New(aws.ErrCodeRequestCanceled,
211211
"request context canceled", err)
212212
r.Retryable = aws.Bool(false)
213213
return

aws/defaults/handlers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestAfterRetryWithContextCanceled(t *testing.T) {
145145

146146
aerr := req.Error.(awserr.Error)
147147

148-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
148+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
149149
t.Errorf("expect %q, error code got %q", e, a)
150150
}
151151
}
@@ -199,7 +199,7 @@ func TestSendWithContextCanceled(t *testing.T) {
199199

200200
aerr := req.Error.(awserr.Error)
201201

202-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
202+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
203203
t.Errorf("expect %q, error code got %q", e, a)
204204
}
205205
}

aws/ec2metadata/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func New(config aws.Config) *EC2Metadata {
5959
Name: defaults.SendHandler.Name,
6060
Fn: func(r *aws.Request) {
6161
r.Error = awserr.New(
62-
aws.CanceledErrorCode,
62+
aws.ErrCodeRequestCanceled,
6363
"EC2 IMDS access disabled via "+disableServiceEnvVar+" env var",
6464
nil)
6565
},

aws/ec2metadata/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestClientDisableIMDS(t *testing.T) {
2828
}
2929

3030
aerr := err.(awserr.Error)
31-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
31+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
3232
t.Errorf("expect %v error code, got %v", e, a)
3333
}
3434
if e, a := "AWS_EC2_METADATA_DISABLED", aerr.Message(); !strings.Contains(a, e) {

aws/request.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ const (
2626
// during body reads.
2727
ErrCodeResponseTimeout = "ResponseTimeout"
2828

29-
// CanceledErrorCode is the error code that will be returned by an
29+
// ErrCodeRequestCanceled is the error code that will be returned by an
3030
// API request that was canceled. Requests given a Context may
3131
// return this error when canceled.
32-
CanceledErrorCode = "RequestCanceled"
32+
ErrCodeRequestCanceled = "RequestCanceled"
3333
)
3434

3535
// A Request is the service request to be made.
@@ -565,7 +565,7 @@ func shouldRetryCancel(r *Request) bool {
565565
timeoutErr := false
566566
errStr := r.Error.Error()
567567
if ok {
568-
if awsErr.Code() == CanceledErrorCode {
568+
if awsErr.Code() == ErrCodeRequestCanceled {
569569
return false
570570
}
571571
err := awsErr.OrigErr()

aws/waiter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (w Waiter) WaitWithContext(ctx Context) error {
193193

194194
// Delay to wait before inspecting the resource again
195195
if err := sdk.SleepWithContext(ctx, w.Delay(attempt)); err != nil {
196-
return awserr.New(CanceledErrorCode, "waiter context canceled", err)
196+
return awserr.New(ErrCodeRequestCanceled, "waiter context canceled", err)
197197
}
198198
}
199199

aws/waiter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ func TestWaiter_WithContextCanceled(t *testing.T) {
523523
t.Fatalf("expect waiter to be canceled.")
524524
}
525525
aerr := err.(awserr.Error)
526-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
526+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
527527
t.Errorf("expect %q error code, got %q", e, a)
528528
}
529529
if e, a := 2, reqCount; e != a {

example/aws/request/withContext/withContext.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func main() {
6363
req.SetContext(ctx)
6464

6565
if _, err := req.Send(); err != nil {
66-
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == request.CanceledErrorCode {
66+
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == request.ErrCodeRequestCanceled {
6767
// If the SDK can determine the request or retry delay was canceled
68-
// by a context the CanceledErrorCode error code will be returned.
68+
// by a context the ErrCodeRequestCanceled error code will be returned.
6969
fmt.Fprintf(os.Stderr, "upload canceled due to timeout, %v\n", err)
7070
} else {
7171
fmt.Fprintf(os.Stderr, "failed to upload object, %v\n", err)

service/s3/s3crypto/decryption_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestGetObjectWithContext(t *testing.T) {
240240
t.Fatalf("expected error, did not get one")
241241
}
242242
aerr := err.(awserr.Error)
243-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
243+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
244244
t.Errorf("expected error code %q, got %q", e, a)
245245
}
246246
if e, a := "canceled", aerr.Message(); !strings.Contains(a, e) {

service/s3/s3crypto/encryption_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestPutObjectWithContext(t *testing.T) {
103103
t.Fatalf("expected error, did not get one")
104104
}
105105
aerr := err.(awserr.Error)
106-
if e, a := aws.CanceledErrorCode, aerr.Code(); e != a {
106+
if e, a := aws.ErrCodeRequestCanceled, aerr.Code(); e != a {
107107
t.Errorf("expected error code %q, got %q", e, a)
108108
}
109109
if e, a := "canceled", aerr.Message(); !strings.Contains(a, e) {

0 commit comments

Comments
 (0)