Stop initialising the IsUnexpected flag to false for new errors #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
IsUnexpected
flag has predominately been designed to support the case that you have an "expected" error (e.g. validation errors that would lead to a 400-like error code) that should actually be seen as "unexpected" (e.g. because the params being validated come from code and not user input), and so fail more noisily.However there is also a sort-of-opposite scenario, where an "unexpected" error wants to be perceived as "expected". An example might be a downstream error from Service B bubbling up to Service A, where Service A handling this error doesn't need to also fail noisily in certain circumstances (e.g. a different team owning each service, where the error will just be noise to the owners of Service A).
This flag has the potential to support this second scenario too, as it has 3 values: nil, true or false. However, we currently initialise all new errors with false, meaning in reality this flag will never be nil, and it's impossible to differentiate between "expected" errors and "normal" errors (ones where we've not set this flag either way, and the normal logic should apply).
This PR changes the default for new errors to not initialise this flag (i.e. it will be nil). This should be a safe change, as long as any calling logic handles the potential nil pointer correctly already - you should check this before pulling in this change.