Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AwesomeWM attempt to index nil value (field 'device') #1

Open
Xart3mis opened this issue Jun 13, 2022 · 8 comments
Open

AwesomeWM attempt to index nil value (field 'device') #1

Xart3mis opened this issue Jun 13, 2022 · 8 comments
Assignees

Comments

@Xart3mis
Copy link

No description provided.

@Aire-One
Copy link
Owner

Aire-One commented Jun 13, 2022

Hello,

To help debugging your issue, can you please provide a full stacktrace of the error thrown as well as a minimal reproducible code example (see https://awesomewm.org/doc/api/documentation/90-FAQ.md.html section "Where are logs, error messages or something?").

It would also help to know what version of awesome you use, and if you have correctly installed the dependencies listed at https://github.com/Aire-One/awesome-battery_widget#dependencies.

@Xart3mis
Copy link
Author

IMG_20220613_185435_edit_42938681466119.jpg
this is the error message that I get
using awesome version : v4.3-1372-g3a542219f (too long)

  • Compiled against Lua 5.4.4 (running with 0.9.2)
  • API level: 4
  • D-Bus support: yes
  • xcb-errors support: no
  • execinfo support: yes
  • xcb-randr version: 1.6
  • LGI version: /usr/share/lua/5.4/lgi/version.lua
  • transparency enabled: yes
  • custom search paths: no

@Aire-One
Copy link
Owner

My best guess right now is that this assignation

widget.device = args.use_display_device
and upower.Client():get_display_device()
or battery_widget.get_device(args.device_path)

went wrong for some reason.

According to https://upower.freedesktop.org/docs/UPower-up-client.html#up-client-get-display-device, the function should return the device or NULL on error.

So a basic check would be for you to run the upower --enumerate command and see if you can find /org/freedesktop/UPower/devices/DisplayDevice in the output.
According to https://upower.freedesktop.org/docs/UPower.html#UPower.GetDisplayDevice, the display device is what should be used by the desktop environment to show the battery level to the user. I don't know what to think on "why it wouldn't exist" or "why the getDisplayDevice function would fail"... I'll need logs to help you investigate further.

The other possibility is that you have turned use_display_device parameter to false and specified something (or not, and in this case something = nil) with the device_path parameter, and this something is not a valid device path.

@Xart3mis
Copy link
Author

upower --enumerate does indeed return /org/freedesktop/UPower/devices/DisplayDevice i'll check the configs and see

@Xart3mis
Copy link
Author

local battery_listener = upower_widget {
    device_path = '/org/freedesktop/UPower/devices/battery_BAT0',
    instant_update = true
}

do you think this could be what was causing the issue

@Aire-One
Copy link
Owner

Given you use the device_path parameter and do not specify use_display_device, it defaults to false. So you are in the branch or battery_widget.get_device(args.device_path).

So, we need to investigate why this code fails :

--- Helper function to get a device instance from its path.
-- @tparam string path The path of the device to get.
-- @treturn UPowerGlib.Device|nil The device if it was found, `nil` otherwise.
-- @staticfct battery_widget.get_device
function battery_widget.get_device(path)
local devices = upower.Client():get_devices()
for _,d in ipairs(devices) do
if d:get_object_path() == path then
return d
end
end
return nil
end

I can have two wild guesses on why it fails :

  1. upower.Client():get_devices() fails and returns an empty list. -> I'd like you to try to investigate that and see what it gives on your system.
  2. d:get_object_path() == path is never verified, in this case it would mean you haven't a '/org/freedesktop/UPower/devices/battery_BAT0' device. This can be checked with upower -e

Hm... There is a third possibility where my code is bad here. I wrote it long ago, don't really remember how I did, and I can't find tests to validate it, so maybe the data-structure returned by get_devices is not iterable by this for loop 🤷

@enuxx
Copy link

enuxx commented Jun 21, 2022

What about if do not have '/org/freedesktop/UPower/devices/battery_BAT0', im having the same error.

@Aire-One
Copy link
Owner

What about if do not have '/org/freedesktop/UPower/devices/battery_BAT0', im having the same error.

First, make sure you actually don't have one by running upower -e.

In the case upower doesn't list a BAT0 entry, you indeed haven't one. You can replace the device_path by whatever upower says. I don't know what upower uses to name the devices, but it shouldn't be a big deal to use something else than BAT0.

(I would however recommend using the display device as shown in the first README example with the parameter use_display_device = true. According to https://upower.freedesktop.org/docs/UPower.html#UPower.GetDisplayDevice, the display device is what should be used by the desktop environment to show the battery level to the user. (I should probably add this to the README 🤔))

@Aire-One Aire-One self-assigned this Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants