protobuf
protobuf copied to clipboard
proto: Export ErrInvalidUTF8
Is your feature request related to a problem? Please describe.
In Golang UTF8 strings are not enforced. Thus, very often some kind of byte sequence is passed through all layers of an application until it finally fails because protobuf eventually checks for UTF-8. This library then returns errInvalidUTF8.
There seem to be 2 solutions to this problem:
-
Checking for UTF-8 on upper layers before passing string down. This would degrade the happy-path unnecessarily and as a consequence is rarely done.
-
React upon the error. Currently, this requires matching the error string. Which is neither idiomatic nor is there any test in this repo to ensure that the string stays the same.
Describe the solution you'd like
To enable errors.Is(err, encoding.ErrInvalidUTF8) I would propose to simply export the error type as well as an error instance while also introducing tests to ensure that said Is works.
Exporting might look like this: var ErrInvalidUTF8 = impl.ErrInvalidUTF8{}.
Describe alternatives you've considered There would be a way to introduce a UTF8String - but this would make the library more non-idiomatic.
Well, this solution would be more idiomatic than the PR linking to this issue…
I proposed golang/go#70547 which would address this in a more ecosystem-wide manner since invalid UTF-8 is not unique to protobuf, but many formats and protocols.