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

When decoding strings, added possibility to choose how to manage errors #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Brosssh
Copy link

@Brosssh Brosssh commented Sep 4, 2024

Context:
I'm using your library since the public API of a game is using protobuf. I'm builing a bot over these API.
While parsing a Message received from this API, I noticed I was getting an exception UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 82: invalid continuation byte. This beacuse the API returned a somehow broken Message, with not UTF8 characters in it. The game is however built in C++, so the behaviour is different, causing no issue in the game but an exception in my bot.
image

By default, Python bytes.decode method is strict, so it crashes in case it goes in errror. This PR aim to change this behaviour by adding a parameter that an user can modify in order to ignore or replace the non UTF8 characters.

Regarding the test case, I could provide the bytes and the Message definition I've used, however it contains a lot of other non relevant fields, can I somehow reduce it to only have the broken part?

Regarding the documentation, I'm not native english speaker/writer so it's probably better if I don't update it myself.

Summary

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR adds something new (e.g. new method or parameters).
    • This change has an associated test.
  • This PR fixes an issue.
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@Brosssh
Copy link
Author

Brosssh commented Sep 4, 2024

I'm also just an amateur coder so please forgive me if my code is not optimal

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.

1 participant