Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: Fix NilError, error non-nil type #187

Merged
merged 1 commit into from Feb 9, 2020

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Feb 6, 2020

The previous fix in #171 incorrectly reported non-nil types as nil errors.
Instead this commit handles the case by using a different error message.

Fixes #185
Fixes #186

@codecov
Copy link

codecov bot commented Feb 6, 2020

Codecov Report

Merging #187 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #187      +/-   ##
==========================================
+ Coverage   84.04%   84.07%   +0.02%     
==========================================
  Files          29       29              
  Lines        2050     2053       +3     
==========================================
+ Hits         1723     1726       +3     
  Misses        224      224              
  Partials      103      103
Impacted Files Coverage Δ
assert/assert.go 82.35% <100%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab4a870...0a11a57. Read the comment docs.

The previous fix incorrectly reported non-nil types as nil errors.
Instead this commit handles the case by using a different error message.
// Handle errors with non-nil types
v := reflect.ValueOf(err)
if v.Kind() == reflect.Ptr && v.IsNil() {
return fmt.Sprintf("error is not nil: error has type %T", err)
Copy link
Contributor

@zikaeroh zikaeroh Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this could include the message if the call doesn't fail (#185 (comment)), since calls on nil are valid so long as the method doesn't try and access its receiver as though it's not nil. That's a further improvement though, and not strictly necessary to fix the other issues. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true. I suspect that most error implementations which use a pointer receiver will require it to be non-nil. I would generally like to avoid the panic/recover, so would prefer to not add it for such a rare case, but it could be done as a future improvement.

@dnephin dnephin merged commit bb0d8a9 into gotestyourself:master Feb 9, 2020
@dnephin dnephin deleted the non-nil-type-errors branch February 9, 2020 21:47
@dnephin
Copy link
Member Author

dnephin commented Feb 9, 2020

tagged v3.0.2 with this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants