Skip to content

Commit 9227042

Browse files
author
Jeffrey D. King
committed
changed cancelled to canceled
1 parent ebd5b24 commit 9227042

File tree

4 files changed

+146
-146
lines changed

4 files changed

+146
-146
lines changed

cancelled.go renamed to canceled.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
status "google.golang.org/grpc/status"
66
)
77

8-
// CancelledError indicates the operation was canceled (typically by the
8+
// CanceledError indicates the operation was canceled (typically by the
99
// caller).
1010
//
1111
// Example error Message:
1212
//
13-
// CANCELLED.
13+
// CANCELED.
1414
//
1515
// HTTP Mapping: 499 CLIENT CLOSED REQUEST
1616
//
17-
// RPC Mapping: CANCELLED
18-
type CancelledError struct {
17+
// RPC Mapping: CANCELED
18+
type CanceledError struct {
1919
Code int `json:"errorCode"`
2020
Message string `json:"errorMessage"`
2121
logMessage string
@@ -24,15 +24,15 @@ type CancelledError struct {
2424
rpcCode codes.Code
2525
}
2626

27-
// NewCancelledError returns a new CancelledError.
28-
func NewCancelledError(Message string, cause ...error) *CancelledError {
27+
// NewCanceledError returns a new CanceledError.
28+
func NewCanceledError(Message string, cause ...error) *CanceledError {
2929
var c error
3030
if len(cause) > 0 {
3131
c = NewErrors(cause...)
3232
}
33-
return &CancelledError{
33+
return &CanceledError{
3434
Code: 499,
35-
Message: "CANCELLED. Request cancelled by the client.",
35+
Message: "CANCELED. Request canceled by the client.",
3636
logMessage: Message,
3737
cause: c,
3838
stack: getTrace(),
@@ -41,27 +41,27 @@ func NewCancelledError(Message string, cause ...error) *CancelledError {
4141
}
4242

4343
// Error implements the error interface
44-
func (e *CancelledError) Error() string { return errorStr(e) }
44+
func (e *CanceledError) Error() string { return errorStr(e) }
4545

4646
// Timeout indicates if this error is the result of a timeout.
47-
func (e *CancelledError) Timeout() bool { return true }
47+
func (e *CanceledError) Timeout() bool { return true }
4848

4949
// Temporary indicates if this error is potentially recoverable.
50-
func (e *CancelledError) Temporary() bool { return false }
50+
func (e *CanceledError) Temporary() bool { return false }
5151

5252
// GetCode returns the HTTP status code associated with this error.
53-
func (e *CancelledError) GetCode() int { return e.Code }
53+
func (e *CanceledError) GetCode() int { return e.Code }
5454

5555
// GetMessage returns the message associated with this error.
56-
func (e *CancelledError) GetMessage() string { return e.Message + " " + e.logMessage }
56+
func (e *CanceledError) GetMessage() string { return e.Message + " " + e.logMessage }
5757

5858
// GetCause returns any causal errors associated with this error.
59-
func (e *CancelledError) GetCause() error { return e.cause }
59+
func (e *CanceledError) GetCause() error { return e.cause }
6060

6161
// GetStack returns the trace stack associated with this error.
62-
func (e *CancelledError) GetStack() stack { return e.stack }
62+
func (e *CanceledError) GetStack() stack { return e.stack }
6363

6464
// GRPCStatus implements an interface required to return proper GRPC status codes
65-
func (e *CancelledError) GRPCStatus() *status.Status {
65+
func (e *CanceledError) GRPCStatus() *status.Status {
6666
return status.New(e.rpcCode, e.Message)
6767
}

canceled_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package errors
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"testing"
7+
8+
assert "github.com/stretchr/testify/assert"
9+
codes "google.golang.org/grpc/codes"
10+
)
11+
12+
type CanceledErrorTest struct {
13+
err *CanceledError
14+
timeout bool
15+
temporary bool
16+
errorInfo string
17+
errorVerbose string
18+
errorDebug string
19+
errorTrace string
20+
getCode int
21+
getMessage string
22+
getCause error
23+
json []byte
24+
rpcCode codes.Code
25+
rpcMessage string
26+
}
27+
28+
var CanceledErrorTests = []CanceledErrorTest{
29+
{
30+
err: NewCanceledError("foo"),
31+
timeout: true,
32+
temporary: false,
33+
errorInfo: "error 499: CANCELED. Request canceled by the client. foo",
34+
getCode: 499,
35+
getMessage: "CANCELED. Request canceled by the client. foo",
36+
getCause: nil,
37+
json: []byte(`{"errorCode":499,"errorMessage":"CANCELED. Request canceled by the client."}`),
38+
rpcCode: codes.Canceled,
39+
rpcMessage: "CANCELED. Request canceled by the client.",
40+
},
41+
{
42+
err: NewCanceledError("foo", errors.New("causal error")),
43+
timeout: true,
44+
temporary: false,
45+
errorInfo: "error 499: CANCELED. Request canceled by the client. foo",
46+
getCode: 499,
47+
getMessage: "CANCELED. Request canceled by the client. foo",
48+
getCause: errors.New("causal error"),
49+
json: []byte(`{"errorCode":499,"errorMessage":"CANCELED. Request canceled by the client."}`),
50+
rpcCode: codes.Canceled,
51+
rpcMessage: "CANCELED. Request canceled by the client.",
52+
},
53+
{
54+
err: NewCanceledError("foo", errors.New("causal error"), errors.New("causal error 2")),
55+
timeout: true,
56+
temporary: false,
57+
errorInfo: "error 499: CANCELED. Request canceled by the client. foo",
58+
getCode: 499,
59+
getMessage: "CANCELED. Request canceled by the client. foo",
60+
getCause: NewErrors(errors.New("causal error"), errors.New("causal error 2")),
61+
json: []byte(`{"errorCode":499,"errorMessage":"CANCELED. Request canceled by the client."}`),
62+
rpcCode: codes.Canceled,
63+
rpcMessage: "CANCELED. Request canceled by the client.",
64+
},
65+
}
66+
67+
func TestCanceledErrorTimeout(t *testing.T) {
68+
for _, test := range CanceledErrorTests {
69+
assert.Equal(t, test.timeout, test.err.Timeout())
70+
}
71+
}
72+
73+
func TestCanceledErrorTemporary(t *testing.T) {
74+
for _, test := range CanceledErrorTests {
75+
assert.Equal(t, test.temporary, test.err.Temporary())
76+
}
77+
}
78+
79+
func TestCanceledErrorError(t *testing.T) {
80+
// note, all other verbosity states tested in error_test.go
81+
SetVerbosity(Info)
82+
for _, test := range CanceledErrorTests {
83+
assert.Equal(t, test.errorInfo, test.err.Error())
84+
}
85+
}
86+
87+
func TestCanceledErrorGetCode(t *testing.T) {
88+
for _, test := range CanceledErrorTests {
89+
assert.Equal(t, test.getCode, test.err.GetCode())
90+
}
91+
}
92+
93+
func TestCanceledErrorGetMessage(t *testing.T) {
94+
for _, test := range CanceledErrorTests {
95+
assert.Equal(t, test.getMessage, test.err.GetMessage())
96+
}
97+
}
98+
99+
func TestCanceledErrorGetCause(t *testing.T) {
100+
for _, test := range CanceledErrorTests {
101+
if test.getCause == nil {
102+
assert.Nil(t, test.err.GetCause())
103+
} else {
104+
assert.Equal(t, test.getCause.Error(), test.err.GetCause().Error())
105+
}
106+
}
107+
}
108+
109+
func TestCanceledErrorGetStack(t *testing.T) {
110+
// trace output prevents testing for string match in different contexts
111+
for _, test := range CanceledErrorTests {
112+
assert.NotNil(t, test.err.GetStack())
113+
}
114+
}
115+
116+
func TestCanceledErrorJson(t *testing.T) {
117+
for _, test := range CanceledErrorTests {
118+
json, _ := json.Marshal(test.err)
119+
assert.Equal(t, string(json[:]), string((test.json)[:]))
120+
}
121+
}
122+
123+
func TestCanceledErrorGrpc(t *testing.T) {
124+
for _, test := range CanceledErrorTests {
125+
s := test.err.GRPCStatus()
126+
assert.Equal(t, test.rpcCode, s.Code())
127+
assert.Equal(t, test.rpcMessage, s.Message())
128+
}
129+
}

cancelled_test.go

Lines changed: 0 additions & 129 deletions
This file was deleted.

errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestErrorsTimeout(t *testing.T) {
196196
timeout bool
197197
}{
198198
{
199-
NewErrors(NewCancelledError("foo")),
199+
NewErrors(NewCanceledError("foo")),
200200
true,
201201
},
202202
{

0 commit comments

Comments
 (0)