digitaltrails / vdu_controls

VDU controls - a control panel for monitor brightness/contrast/...
GNU General Public License v3.0
103 stars 4 forks source link

Fixed utf-8 decoding error #49

Closed denilsonsa closed 1 year ago

denilsonsa commented 1 year ago

Fixed this error:

ERROR: 'utf-8' codec can't decode byte 0x80 in position 2818: invalid start byte

It happens because indeed there is a 0x80 byte in the middle of Extra descriptor at the EDID information. Look:

image

   EDID hex dump:
              +0          +4          +8          +c            0   4   8   c   
      +0000   00 ff ff ff ff ff ff 00 06 af 2d 56 00 00 00 00   ..........-V....
      +0010   00 1c 01 04 a5 1d 11 78 02 ee 95 a3 54 4c 99 26   .......x....TL.&
      +0020   0f 50 54 00 00 00 01 01 01 01 01 01 01 01 01 01   .PT.............
      +0030   01 01 01 01 01 01 b4 37 80 a0 70 38 3e 40 3a 2a   .......7..p8>@:*
      +0040   35 00 25 a5 10 00 00 1a b4 37 80 a0 70 38 5c 41   5.%......7..p8\A
      +0050   3a 2a 35 00 25 a5 10 00 00 1a 00 00 00 fe 00 38   :*5.%..........8
      +0060   34 58 46 37 80 42 31 33 33 48 41 4e 00 00 00 00   4XF7.B133HAN....
      +0070   00 02 41 03 9e 00 11 00 00 0a 01 0a 20 20 00 c4   ..A.........  ..

This, by the way, is reported as Invalid display, because This is an eDP laptop display. Laptop displays do not support DDC/CI.


Bonus: Tracking down this error was annoying because the try…except block at line 6531 swallows the stacktrace. I managed to view the stacktrace by adding a plain raise line in the except block, effectively re-throwing the error. Maybe the stacktrace should be printed if --debug is passed. I'll leave the implementation as an exercise to someone else. ;)

digitaltrails commented 1 year ago

Thanks fo the patch. I shall raise an issue about adding more debugging.

I would like to support laptops by providing a wrapper around ddcutil that would support a subset of commands - see #44. But I don't own any laptops, maybe one day (probably not though).

denilsonsa commented 1 year ago

There may be other uses of .decode() that can throw the same error, but I haven't investigated any further.

digitaltrails commented 12 months ago

There may be other uses of .decode() that can throw the same error, but I haven't investigated any further.

I will be looking at any other decode() calls.

digitaltrails commented 12 months ago

I changed errors='replace' to errors='surrogateescape' in an attempt to retain as much info as possible. I've put this in place in almost every instance where decode is used.

In many cases decode is issued when creating diagnostics, leaving an escaped representation of the offending character should be safe. I'm sure about what will happen if a decoded surrogateescape value is used functionally, but I don't think that is likely to happen.