Skip to content

Commit f93c635

Browse files
authored
Merge pull request #54 from monzo/fix-initialisation-of-is-unexpected-flag
Stop initialising the IsUnexpected flag to false for new errors
2 parents 073654f + 3c71ada commit f93c635

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ func (p *Error) Retryable() bool {
218218
}
219219

220220
// Unexpected states whether an error is not expected to occur. In many cases this will be due to a bug, e.g. due to a
221-
// defensive check failing
221+
// defensive check failing.
222+
// Note that if the IsUnexpected flag has not been set at all, this will still return false.
222223
func (p *Error) Unexpected() bool {
223224
if p.IsUnexpected != nil {
224225
return *p.IsUnexpected

errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func TestSetIsRetryable(t *testing.T) {
575575

576576
func TestSetIsUnexpected(t *testing.T) {
577577
err := New("code", "message", nil)
578-
assert.False(t, *err.IsUnexpected)
578+
assert.Nil(t, err.IsUnexpected)
579579

580580
err.SetIsUnexpected(true)
581581
assert.True(t, *err.IsUnexpected)

factory.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ func RateLimited(code, message string, params map[string]string) *Error {
117117
// Builds a stack based on the current call stack
118118
func errorFactory(code string, message string, params map[string]string) *Error {
119119
err := &Error{
120-
Code: ErrUnknown,
121-
Message: message,
122-
Params: map[string]string{},
123-
IsUnexpected: &notUnexpected,
120+
Code: ErrUnknown,
121+
Message: message,
122+
Params: map[string]string{},
124123
}
125124
if len(code) > 0 {
126125
err.Code = code

0 commit comments

Comments
 (0)