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

Improve ErrorIs message when error is nil but an error was expected #1681

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tsioftas
Copy link

Summary

This improves the UX of users of ErrorIs() in case the value nil is passed for err while an error was expected.

Changes

  • added check if err == nil && target != nil -> return a special error-string
  • updated relevant test case

Motivation

The error message when an error is expected but err is nil (a common occurence in the world of testing) could be more helpful, e.g.:

(before)
some_test.go:20:
                Error Trace:    /[...]/some_test.go:20
                Error:          Target error should be in err chain:
                                expected: "sample error message"
                                in chain:

vs

(after)
some_test.go:20:
                Error Trace:    /[...]/some_test.go:20
                Error:          Expected error "sample error message" but got nil.

@tsioftas tsioftas marked this pull request as draft November 18, 2024 12:21
@tsioftas tsioftas marked this pull request as ready for review November 18, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants