Skip to content

Commit

Permalink
Merge pull request #54 from monzo/fix-initialisation-of-is-unexpected…
Browse files Browse the repository at this point in the history
…-flag

Stop initialising the IsUnexpected flag to false for new errors
  • Loading branch information
tompreston authored Sep 3, 2024
2 parents 073654f + 3c71ada commit f93c635
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func (p *Error) Retryable() bool {
}

// 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
// defensive check failing
// defensive check failing.
// Note that if the IsUnexpected flag has not been set at all, this will still return false.
func (p *Error) Unexpected() bool {
if p.IsUnexpected != nil {
return *p.IsUnexpected
Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func TestSetIsRetryable(t *testing.T) {

func TestSetIsUnexpected(t *testing.T) {
err := New("code", "message", nil)
assert.False(t, *err.IsUnexpected)
assert.Nil(t, err.IsUnexpected)

err.SetIsUnexpected(true)
assert.True(t, *err.IsUnexpected)
Expand Down
7 changes: 3 additions & 4 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ func RateLimited(code, message string, params map[string]string) *Error {
// Builds a stack based on the current call stack
func errorFactory(code string, message string, params map[string]string) *Error {
err := &Error{
Code: ErrUnknown,
Message: message,
Params: map[string]string{},
IsUnexpected: &notUnexpected,
Code: ErrUnknown,
Message: message,
Params: map[string]string{},
}
if len(code) > 0 {
err.Code = code
Expand Down

0 comments on commit f93c635

Please sign in to comment.