Fixed a "UnicodeDecodeError: 'utf-8' codec can't decode byte" // Resolve #3804 , Resolve #3417

This commit is contained in:
Ivan Kravets
2021-01-20 20:45:23 +02:00
parent 5a356140d6
commit 52b22b5784
2 changed files with 13 additions and 8 deletions

View File

@ -15,6 +15,8 @@ PlatformIO Core 5
* Improved listing of `multicast DNS services <https://docs.platformio.org/page/core/userguide/device/cmd_list.html>`_
* Check for debug server's "ready_pattern" in "stderr"
* Upgraded build engine to the SCons 4.1 (`release notes <https://scons.org/scons-410-is-available.html>`_)
* Fixed a "UnicodeDecodeError: 'utf-8' codec can't decode byte" when using J-Link for a firmware uploading on Linux (`issue #3804 <https://github.com/platformio/platformio-core/issues/3804>`_)
* Fixed an issue with Python 3.8+ on Windows when network drive is used (`issue #3417 <https://github.com/platformio/platformio-core/issues/3417>`_)
5.0.4 (2020-12-30)
~~~~~~~~~~~~~~~~~~

View File

@ -32,7 +32,10 @@ from platformio.compat import (
class AsyncPipeBase(object):
def __init__(self):
self._fd_read, self._fd_write = os.pipe()
self._pipe_reader = os.fdopen(self._fd_read)
if PY2:
self._pipe_reader = os.fdopen(self._fd_read)
else:
self._pipe_reader = os.fdopen(self._fd_read, errors="backslashreplace")
self._buffer = ""
self._thread = Thread(target=self.run)
self._thread.start()
@ -68,10 +71,10 @@ class BuildAsyncPipe(AsyncPipeBase):
line = ""
print_immediately = False
for byte in iter(lambda: self._pipe_reader.read(1), ""):
self._buffer += byte
for char in iter(lambda: self._pipe_reader.read(1), ""):
self._buffer += char
if line and byte.strip() and line[-3:] == (byte * 3):
if line and char.strip() and line[-3:] == (char * 3):
print_immediately = True
if print_immediately:
@ -79,12 +82,12 @@ class BuildAsyncPipe(AsyncPipeBase):
if line:
self.data_callback(line)
line = ""
self.data_callback(byte)
if byte == "\n":
self.data_callback(char)
if char == "\n":
print_immediately = False
else:
line += byte
if byte != "\n":
line += char
if char != "\n":
continue
self.line_callback(line)
line = ""