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

proto: Export ErrInvalidUTF8 #1642

Open
AndreasBergmeier6176 opened this issue Aug 20, 2024 · 1 comment
Open

proto: Export ErrInvalidUTF8 #1642

AndreasBergmeier6176 opened this issue Aug 20, 2024 · 1 comment

Comments

@AndreasBergmeier6176
Copy link

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:

  1. 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.

  2. 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.

@puellanivis
Copy link
Collaborator

Well, this solution would be more idiomatic than the PR linking to this issue…

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

No branches or pull requests

2 participants