machinekit / machinetalk-protobuf

Protobuf declarations for machinekit messages
MIT License
10 stars 11 forks source link

Fix unicode problem in protoc-gen-depends #23

Closed bobvanderlinden closed 8 years ago

bobvanderlinden commented 9 years ago

When running make, I had the following error:

Traceback (most recent call last):
  File "scripts/protoc-gen-depends", line 25, in <module>
    req.MergeFromString(''.join(stdin.readlines()))
  File "/usr/lib/python3.4/codecs.py", line 319, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 161: invalid continuation byte
--depends_out: protoc-gen-depends: Plugin failed with status code 1.

It was caused by stdin being read as a text-stream (default for sys.stdin). My machine is configured to use UTF-8 as text-encoding and in turn it seemed Python couldn't decode the stream as UTF-8.

This change uses sys.stdin.buffer, instead of sys.stdin, which should read bytes instead of encoded-text-strings.

bobvanderlinden commented 9 years ago

Oh, I must add that I'm not 100% sure whether the output that protoc-gen-depends generates is actually correct (I have not tested the .d files), but everything still functions the same way, except that byte-strings are used instead of text-strings.

bobvanderlinden commented 8 years ago

Found a nicer way to read all bytes from stdin. This will make the code a bit simpler, but still just reads bytes (without using any text-encoding).

machinekoder commented 8 years ago

Well done, you could rebase the second commit as fixup to keep the history clean.

bobvanderlinden commented 8 years ago

Alright, fixed up original commit with the simplified calls.

bobvanderlinden commented 8 years ago

Thanks!

On Wed, Sep 2, 2015 at 7:40 AM Michael Haberler notifications@github.com wrote:

Merged #23 https://github.com/machinekit/machinetalk-protobuf/pull/23.

— Reply to this email directly or view it on GitHub https://github.com/machinekit/machinetalk-protobuf/pull/23#event-398550721 .