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

Prevent a crash in case the output of the command is not a valid utf-8 sequence. #211

Conversation

Natim
Copy link

@Natim Natim commented Feb 15, 2017

Fixes #210

@Natim Natim force-pushed the 210-prevent-crash-if-command-output-is-not-utf-8 branch from 3a15b27 to 60846e9 Compare February 15, 2017 13:05
try:
stdout_output = stdout_output.decode(OUTPUT_ENCODING)
except UnicodeDecodeError:
stdout_output = '%s stdout output is not a valid %s stream.' % (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... instead of getting back output from, for instance, "git diff" we now get an error message?

This silences the error: is this always a good thing?

Copy link
Author

@Natim Natim Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to handle that would be not to decode the output.

Since we are printing it back we could just keep it as bytes instead so that the terminal would have to handle the display and it would look really close to the original one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good thing to silence the error?

To be honest I don't think we should crash on UnicodeDecodeError then my solution might not be the right one, we should talk about it and see how we want to handle it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do .decode('utf-8', 'replace').

@mauritsvanrees
Copy link
Member

If this is still a problem, please try with latest version 7.0.0a1. Python 3 only, so maybe encoding problems have gone away.

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.

git diff encoding different from UTF-8
3 participants