Commit e1df6c1
committed
agents/sysfsgpio: fix misleading Python error when permission denied
If the executor doesn't have the proper permissions to control the GPIO
or export it, a Permission Denied will be raised. However, __del__ is
called regardless and gpio_sysfs_value_fd attribute isn't present if the
__init__ doesn't finish.
Thus, Python prints the following:
"""
Exception ignored in: <function GpioDigitalOutput.__del__ at 0x7f5b017f80e0>
Traceback (most recent call last):
File "<loaded sysfsgpio>", line 44, in __del__
AttributeError: 'GpioDigitalOutput' object has no attribute 'gpio_sysfs_value_fd'
""" before the raised Exception, possibly misleading the user on their
debugging quest.
Therefore, let's make sure the attribute exists before anything can
throw an Exception in __init__.
os.close() can only be called on a valid file descriptor, which None
isn't, therefore only call os.close() if self.gpio_sysfs_value_fd is not
None.
Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>1 parent 4398da7 commit e1df6c1
1 file changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
0 commit comments