wendlers / mpfshell

A simple shell based file explorer for ESP8266 Micropython based devices ⛺
MIT License
396 stars 84 forks source link

codec can't decode byte #111

Closed kr-g closed 1 year ago

kr-g commented 1 year ago

during startup my esp32 board returns (sometimes) crazy data causing mpfshell to fail

Traceback (most recent call last):
  File "/home/xx/repo/mpfshell/mpfshell.py", line 5, in <module>
    sys.exit(main())
  File "/home/xx/repo/mpfshell/mp/mpfshell.py", line 914, in main
    mpfs.onecmd(scmd)
  File "/usr/lib/python3.10/cmd.py", line 217, in onecmd
    return func(arg)
  File "/home/xx/repo/mpfshell/mp/mpfshell.py", line 564, in do_exec
    ret = self.fe.follow(None, data_consumer)
  File "/home/xx/repo/mpfshell/mp/pyboard.py", line 105, in follow
    data = self.read_until(1, b"\x04", timeout=timeout, data_consumer=data_consumer)
  File "/home/xx/repo/mpfshell/mp/pyboard.py", line 48, in read_until
    data_consumer(new_data)
  File "/home/xx/repo/mpfshell/mp/mpfshell.py", line 556, in data_consumer
    data = str(data.decode("utf-8"))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 0: unexpected end of data

https://github.com/wendlers/mpfshell/blob/3ac8f401077971b2026e51f2c2180bd7b71157a5/mp/mpfshell.py#L554-L558

kr-g commented 1 year ago

i did some more investigations here. data_consumer is a callback from MpFileExplorer inherited from Pyboard.follow method what will call again read_until

https://github.com/wendlers/mpfshell/blob/3ac8f401077971b2026e51f2c2180bd7b71157a5/mp/pyboard.py#L35-L49

here it reads a single byte from the incoming stream and calls directly the consumer.

remark: UTF-8 is multi-byte