Implement an error-comparing method to errorsx String #841
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.
PR preparation
What
Is()
to the structString
in the packageerrorsx
errorsx
on the way to make a test for this funcWhy
To make it possible to compare the custom error (
String
inerrorsx
) with all the struct implementingerror
interface byerrors.Is
.That enables users of this package to check returned exported errors in their own applications by the latest Go standard error comparing way.
For example, the package user can handle the returned error like this
From Go1.13,
errors.Is
is provided as a function of a Go standard package.And, to make the custom error comparable by this func, we need to implement
Is
method to that.From the package description of errors
Note
Firstly I meant and tried to update result evaluation in some test files by this func, but it was too early considering the consistency for the old Go version. So, now I propose this func just for increasing the package user's options to check the returned error from this package.