ros-drivers/nmea_navsat_driver

nmea_serial_driver terminates due to unhandled UnicodeDecodeError upon receiving a corrupted sentence

donkikos opened this issue · 5 comments

The new release for noetic gives error. Trying to use with GlobalSat BU-353-S4.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal
$ rosrun nmea_navsat_driver nmea_serial_driver _port:=/dev/gps _baud:=4800
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/nmea_navsat_driver/nmea_serial_driver", line 38, in <module>
    libnmea_navsat_driver.nodes.nmea_serial_driver.main()
  File "/opt/ros/noetic/lib/python3/dist-packages/libnmea_navsat_driver/nodes/nmea_serial_driver.py", line 67, in main
    nmea_str = data.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 6: invalid continuation byte

Thanks for reporting this. I think I know what's happening here. NMEA strings should be ASCII-encoded, but the first sentence from the serial device often contains some garbage data, which is very likely to include bytes outside of the ASCII table (and in this case outside of the utf-8 table even). I'll put up a fix shortly that discards such data so that the node doesn't crash in this case.

@donkikos Would you mind reviewing PR #116?

Sure, @evenator will test with the receiver I got.

I was patching by changing the decode('utf-8') with decode(encoding='utf-8', errors='ignore') and seems it was working.

I considered errors='ignore' as a solution as well. I decided that it would be better to catch the error and print a warning, because otherwise the driver might silently discard all data (like if the baud rate was set incorrectly).

@evenator I tested the nmea_serial_driver node. No crashes as of now. Thanks for the fix!

I considered errors='ignore' as a solution as well. I decided that it would be better to catch the error and print a warning, because otherwise the driver might silently discard all data (like if the baud rate was set incorrectly).

I agree.