pyserial errorhandling in plotter.py tries to iterate over wrong Exception attribute

Bug #1650480 reported by seahawk1986
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Low
jazzynico
0.92.x
Fix Released
Low
jazzynico

Bug Description

When opening the serial connection using pyserial 3.x in plotter.py fails ( https://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/view/head:/share/extensions/plotter.py#L196 ), the script looks at the wrong element of the exception (which results in raising another Exception like in this post: https://forum.ubuntuusers.de/post/8682508/ ):

Traceback (most recent call last):
  File "plotter.py", line 227, in <module>
    e.affect()
  File "/usr/share/inkscape/extensions/inkex.py", line 268, in affect
    self.effect()
  File "plotter.py", line 96, in effect
    self.sendHpglToSerial()
  File "plotter.py", line 162, in sendHpglToSerial
    if 'ould not open port' in inst.args[0]:
TypeError: argument of type 'int' is not iterable

Minimal example in the python interpreter (somehow launchpad ignores the spaces before the commands in the lines after try and except when displaying the text):
>>> import serial
>>> mySerial = serial.Serial()
>>> mySerial.port = '/dev/ttyS0'
>>> try:
... mySerial.open()
... except Exception as inst:
... inst.args
... inst.args[0]
... inst.strerror
...
(13, "could not open port /dev/ttyS0: [Errno 13] Keine Berechtigung: '/dev/ttyS0'")
13
"could not open port /dev/ttyS0: [Errno 13] Keine Berechtigung: '/dev/ttyS0'"

It should be more reliable to use the inst.strerror Attribute of the Exception or str(inst) instead of an index-Based value in the Exception.

description: updated
description: updated
description: updated
Revision history for this message
jazzynico (jazzynico) wrote :

Thanks for taking the time to file a report!

Bug reproduced on Xubuntu 16.04, Inkscape 0.91 and lp:inkscape/0.92.x rev.15315.

Changed in inkscape:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
jazzynico (jazzynico) wrote :
Changed in inkscape:
assignee: nobody → jazzynico (jazzynico)
milestone: none → 0.93
status: Triaged → In Progress
tags: added: exporting
removed: python
Revision history for this message
jazzynico (jazzynico) wrote :

Patch committed in lp:inkscape rev. 15413.
Proposing to backport to 0.92.1.

Changed in inkscape:
status: In Progress → Fix Committed
tags: added: backport-proposed
Revision history for this message
Bryce Harrington (bryce) wrote :

+1 for backport to 0.92.1.

Thanks jazzynico for the fix, and seahawk1986 for the analysis.

Revision history for this message
jazzynico (jazzynico) wrote :

Fixed in lp:inkscape/0.92.x rev. 15316.

jazzynico (jazzynico)
tags: removed: backport-proposed
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.