jaraco / irc

Full-featured Python IRC library for Python.
MIT License
390 stars 85 forks source link

reactor crashes if channel contains invalid UTF-8 characters #100

Closed dmerejkowsky closed 8 years ago

dmerejkowsky commented 8 years ago

Using basic example, the client crashes with:

        self.reactor.process_once(timeout)
      File "/home/marvin/.local/lib/python3.4/site-packages/irc/client.py", line 259, in process_once
        self.process_data(i)
      File "/home/marvin/.local/lib/python3.4/site-packages/irc/client.py", line 216, in process_data
        c.process_data()
      File "/home/marvin/.local/lib/python3.4/site-packages/irc/client.py", line 579, in process_data
        for line in self.buffer:
      File "/home/marvin/.local/lib/python3.4/site-packages/jaraco/stream/buffer.py", line 104, in lines
        self.handle_exception()
      File "/home/marvin/.local/lib/python3.4/site-packages/jaraco/stream/buffer.py", line 102, in lines
        yield line.decode(self.encoding, self.errors)

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 58: invalid continuation byte

Digging a little bit, I found the following workaround:


reactor = irc.client.Reactor()

server = reactor.server()
# Ignore encoding errors:
server.buffer_class = jaraco.stream.buffer.LenientDecodingLineBuffer

Maybe this should be done by default, instead of using DecodingLineBuffer? It's common to see mis-configured IRC clients, even in 2016 :P

Or at least we could patch the documentation ...

jaraco commented 8 years ago

Please see the readme, and if you have suggestions for improving the documentation to make this issue more clear, feel free to submit a PR.

dmerejkowsky commented 8 years ago

My bad, I somehow missed this part of the README :)

Anyway, code was written well enough that the solution was easy to find. Kudos!