structtag
structtag copied to clipboard
Unexported error sentinel values
https://github.com/fatih/structtag/blob/2977b8db49bbf5ae2e0ae2be55e43d2c1798fc03/tags.go#L11-L19
Is there a particular reason these error sentinel values are unexported? Because of this I have to match errors by message, which is obviously bad:
tag, err := tags.Get(expectTag)
switch {
case err.Error() == "tag does not exist":
// handle errTagNotExist
case err != nil:
// handle other errors
}
Instead, it should be:
tag, err := tags.Get(expectTag)
switch {
case errors.Is(err, structtag.ErrTagNotExist):
// handle
case err != nil:
// handle other errors
}
I propose exporting error sentinel values. Such a change would be backward compatible anyway.
Hi @romshark
There are no particular reasons for that. The only thing was I didn't wanted to make it part of the public API, because then it would mean I wouldn't be able to make any changes. So it's an additional layer of maintenance we have to take care of. I wrote it here: https://github.com/fatih/structtag/pull/16
But given the fact this is something people rely on it, I think it makes sense to expose them.
Would you mind opening a PR? The https://github.com/fatih/structtag/pull/16 is not mergable anymore. Let's fix this.