libratbag / piper

GTK application to configure gaming devices
GNU General Public License v2.0
4.79k stars 177 forks source link

TypeError: 'NoneType' object is not iterable - RatbagdLed(objpath) for objpath in result #166

Closed michaellarabel closed 6 years ago

michaellarabel commented 7 years ago

Hi @Hjdskes nice GSoC work, Trying out the Git piper code with a Logitech G300s, which looks like it should be supported by libratbag. But when running piper after connecting the mouse, I am getting:

$ piper Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/piper/application.py", line 45, in do_startup self._ratbag = Ratbagd() File "/usr/lib/python3.6/site-packages/piper/ratbagd.py", line 236, in init self._devices = [RatbagdDevice(objpath) for objpath in result] File "/usr/lib/python3.6/site-packages/piper/ratbagd.py", line 236, in self._devices = [RatbagdDevice(objpath) for objpath in result] File "/usr/lib/python3.6/site-packages/piper/ratbagd.py", line 291, in init self._profiles = [RatbagdProfile(objpath) for objpath in result] File "/usr/lib/python3.6/site-packages/piper/ratbagd.py", line 291, in self._profiles = [RatbagdProfile(objpath) for objpath in result] File "/usr/lib/python3.6/site-packages/piper/ratbagd.py", line 374, in init self._leds = [RatbagdLed(objpath) for objpath in result] TypeError: 'NoneType' object is not iterable

Presumably since there aren't controlable LEDs on the mouse (or so I am guessing, just picked up the mouse today) or for what's exposed?

(Not sure if it's related but after connecting the mouse from the ratbagd service I do see a ratbagd[2654]: ratbagd error: Unable to find active resolution for event5 )

Hjdskes commented 7 years ago

This is easy to fix with the following diff:

diff --git a/piper/ratbagd.py b/piper/ratbagd.py
index ec601cf..c9153ea 100644
--- a/piper/ratbagd.py
+++ b/piper/ratbagd.py
@@ -395,16 +395,19 @@ class RatbagdProfile(_RatbagdDBus):
         # FIXME: if we start adding and removing objects from any of these
         # lists, things will break!
         result = self._get_dbus_property("Resolutions")
-        self._resolutions = [RatbagdResolution(objpath) for objpath in result]
-        self._subscribe_dirty(self._resolutions)
+        if result is not None:
+            self._resolutions = [RatbagdResolution(objpath) for objpath in result]
+            self._subscribe_dirty(self._resolutions)

         result = self._get_dbus_property("Buttons")
-        self._buttons = [RatbagdButton(objpath) for objpath in result]
-        self._subscribe_dirty(self._buttons)
+        if result is not None:
+            self._buttons = [RatbagdButton(objpath) for objpath in result]
+            self._subscribe_dirty(self._buttons)

         result = self._get_dbus_property("Leds")
-        self._leds = [RatbagdLed(objpath) for objpath in result]
-        self._subscribe_dirty(self._leds)
+        if result is not None:
+            self._leds = [RatbagdLed(objpath) for objpath in result]
+            self._subscribe_dirty(self._leds)

     def _subscribe_dirty(self, objects):
         for obj in objects:

However, I wonder if there is a better way: this crash happens because I assumed that if a device has no LEDs (for example), the property would return an empty list and not None. Looking at ratbagd_profile_get_leds, this is what I assumed would happen; i.e. the container is opened, for every led (none) a path gets added, and the container is closed and sent over the bus. @whot can we somehow make this happen, or should we go for the diff above?

michaellarabel commented 7 years ago

Hi @Hjdskes after applying the patch:

$

piper No active profile. Please report this bug to the libratbag developers Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/piper/application.py", line 52, in do_activate window = Window(self._ratbag, application=self) File "/usr/lib/python3.6/site-packages/piper/window.py", line 67, in init self._present_mouse_perspective(ratbag.devices[0]) File "/usr/lib/python3.6/site-packages/piper/window.py", line 150, in _present_mouse_perspective mouse_perspective.set_device(device) File "/usr/lib/python3.6/site-packages/piper/mouseperspective.py", line 106, in set_device row = ProfileRow(profile) File "/usr/lib/python3.6/site-packages/piper/profilerow.py", line 44, in init self.set_visible(profile.enabled) TypeError: Argument 1 does not allow None as a value

Hjdskes commented 7 years ago

If #168 doesn't fix that, can you show me the output of sudo ./build/ratbagctl info <device> from the libratbag root directory after building libratbag? If it's not #168 I suspect it's an issue with libratbag rather than Piper.

whot commented 7 years ago

@michaellarabel what version of libratbag are you running?

@Hjdskes

this crash happens because I assumed that if a device has no LEDs (for example), the property would return an empty list and not None.

printf debugging here shows that this is happening

diff --git a/tools/ratbagd.py b/tools/ratbagd.py
index 5f889aa..3e36c27 100644
--- a/tools/ratbagd.py
+++ b/tools/ratbagd.py
@@ -164,6 +164,7 @@ class _RatbagdDBus(GObject.GObject):
     def _get_dbus_property(self, property):
         # Retrieves a cached property from the bus, or None.
         p = self._proxy.get_cached_property(property)
+        print("property {}: {}".format(property, p))
         if p is not None:
             return p.unpack()
         return p
@@ -405,8 +406,10 @@ class RatbagdProfile(_RatbagdDBus):
         result = self._get_dbus_property("Buttons")
         self._buttons = [RatbagdButton(objpath) for objpath in result]
         self._subscribe_dirty(self._buttons)
+        print("::::::::::::::::::::::::::: fetching leds")

         result = self._get_dbus_property("Leds")
+        print("result is {}".format(result))
         self._leds = [RatbagdLed(objpath) for objpath in result]
         self._subscribe_dirty(self._leds)

output:

/org/freedesktop/ratbag_devel1_8d41fee/button/test_5fdevice/p3/b3']
::::::::::::::::::::::::::: fetching leds
property Leds: @ao []
result is []

No changes should be needed to ratbagd.py

michaellarabel commented 7 years ago

@whot it should have been Git from ~4 days ago.

Hjdskes commented 7 years ago

No changes should be needed to ratbagd.py

That's good to know; I couldn't test this myself since the only device I have (G403) behaves correctly. Since ratbagd and the bindings are then behaving correctly, this must be a driver issue?

@michaellarabel can check with the latest master branch of both Piper and libratbag? If the behaviour still occurs, please show me the output of sudo ./build/ratbagctl info <device> from the libratbag root directory after building libratbag.

michaellarabel commented 7 years ago

Hi @Hjdskes I sinced moved onto other tests but will probably be back trying out libratbag+Piper in a few days.

konstantinblaesi commented 7 years ago

I am on Fedora 27 beta and disabled SELinux temporarily because I had issues getting it to work otherwise.

I installed libratbag master and piper master with the patch from above.

piper

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/piper/application.py", line 52, in do_activate
    window = Window(self._ratbag, application=self)
  File "/usr/lib/python3.6/site-packages/piper/window.py", line 67, in __init__
    self._present_mouse_perspective(ratbag.devices[0])
  File "/usr/lib/python3.6/site-packages/piper/window.py", line 150, in _present_mouse_perspective
    mouse_perspective.set_device(device)
  File "/usr/lib/python3.6/site-packages/piper/mouseperspective.py", line 86, in set_device
    self.stack.add_titled(ResolutionsPage(device), "resolutions", _("Resolutions"))
  File "/usr/lib/python3.6/site-packages/piper/resolutionspage.py", line 67, in __init__
    self._init_ui()
  File "/usr/lib/python3.6/site-packages/piper/resolutionspage.py", line 84, in _init_ui
    row = ResolutionRow(self._device, resolution)
  File "/usr/lib/python3.6/site-packages/piper/resolutionrow.py", line 49, in __init__
    self._init_values(resolution)
  File "/usr/lib/python3.6/site-packages/piper/resolutionrow.py", line 69, in _init_values
    self.scale.props.adjustment.configure(xres, minres, maxres, 50, 50, 0)
TypeError: Argument 2 does not allow None as a value

ratbagctl

event3:    Logitech Gaming Mouse G900

ratbagctl info event3

event3 - Logitech Gaming Mouse G900
               SVG: /usr/share/libratbag/gnome/logitech-g900.svg
      Capabilities: query-configuration, resolution, switchable-resolution, profile, switchable-profile, disable-profile, button, button-keys, led
 Number of Buttons: 12
    Number of Leds: 2
Number of Profiles: 5
Profile 0: (active)
  Name : 'Profile 1'
  Resolutions:
    0: 400dpi @ 1000Hz
    1: 800dpi @ 1000Hz (active) (default)
    2: 1600dpi @ 1000Hz
    3: 3200dpi @ 1000Hz
    4: <disabled>
  Button: 0 type unknown is mapped to 'button 1'
  Button: 1 type unknown is mapped to 'button 2'
  Button: 2 type unknown is mapped to 'button 3'
  Button: 3 type unknown is mapped to 'button 4'
  Button: 4 type unknown is mapped to 'button 5'
  Button: 5 type unknown is mapped to 'button 4'
  Button: 6 type unknown is mapped to 'button 5'
  Button: 7 type unknown is mapped to 'resolution-down'
  Button: 8 type unknown is mapped to 'resolution-up'
  Button: 9 type unknown is mapped to 'wheel-left'
  Button: 10 type unknown is mapped to 'wheel-right'
  Button: 11 type unknown is mapped to 'profile-cycle-up'
  LED: 0 type: logo, depth: rgb, mode: cycle, rate: 8000, brightness: 255
  LED: 1 type: side, depth: rgb, mode: cycle, rate: 8000, brightness: 255
Profile 1: (disabled)
Profile 2: (disabled)
Profile 3: (disabled)
Profile 4: (disabled)

Ideas? Chances of getting updated libratbag/piper packages for fedora 27 soon?

Hjdskes commented 7 years ago

@konstantinblaesi That is a different issue from the one described here and should be resolved once #186 is merged.

Verifirs commented 6 years ago

This is still an issue, has not been resolved. Are there any fixes available?

Hjdskes commented 6 years ago

No, not yet. I suspect this is an issue in libratbag rather than Piper, and the libratbag developers are at the moment occupied with other work.

phomes commented 6 years ago

@Verifirs This issue was originally created for the Logitech G300s. The driver for that device has seen many updates since and does not show this problem for me today. Do you have that same mouse or do you see the same issue for a different mouse? @michaellarabel it would be great if you could retest that the original issue is fixed.

Verifirs commented 6 years ago

@phomes I own the Logitech G303 mouse and I see the same issue.

phomes commented 6 years ago

@Verifirs Ok. The G300/G300s actually uses a different driver than the G303. The symptom is the same but it is possibly two different problems. The G300s should be working and it would be great if @michaellarabel could check if the issue is fixed for him.

The G303 is using the hidpp20 driver. I do not have that mouse available so I cannot test. Did you test from git or a version from your distribution? Could you describe how you are starting ratbagd and piper?

Verifirs commented 6 years ago

@phomes Good news! Upon compiling the latest git version of libratbagd and piper, the issue has been resolved. The version I was using before was from a copr repo that was two months out of date.

whot commented 6 years ago

5fbeacc447ea6f3f6795b61ce89e557313606e4d should've fixed a bunch of others related issues like this, let's close this and re-open it if it comes back.