joshuar / go-hass-agent

A Home Assistant, native app for desktop/laptop devices.
MIT License
128 stars 9 forks source link

[BUG] Crash when geoclue is not installed #186

Closed whitelynx closed 2 months ago

whitelynx commented 2 months ago

Go Hass Agent Version

11:35PM INF Go Hass Agent: v9.3.0-75-gbfc0c89-dirty

Describe the bug Crash at startup (SIGSEGV) when Geoclue2 is not installed.

To Reproduce Steps to reproduce the behaviour:

  1. Don't install Geoclue2.
  2. Register using the GUI (go-hass-agent register --force)
  3. go-hass-agent run
  4. See error.

Expected behaviour It shouldn't crash, and instead should just ignore the location sensor.

Logs

10:03PM WRN Could not activate a worker. error="unable to monitor for active applications: no portal present"
10:03PM WRN Could not activate a worker. error="unable to monitor for desktop settings: no portal present"
10:03PM WRN Could not activate a worker. error="unsupported hardware for laptop sensor monitoring"
10:03PM ERR Could not set up a geoclue client. error="SystemBus: unable to get data org.freedesktop.GeoClue2.Manager.GetClient from org.freedesktop.GeoClue2: The name org.freedesktop.GeoClue2 was not provided by any .service files"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0xd19a9d]

goroutine 83 [running]:
github.com/joshuar/go-hass-agent/pkg/linux/dbusx.WatchBus({0x11b9198, 0xc00071c2d0}, 0x0)
    /home/whitelynx/Development/Other/go-hass-agent/pkg/linux/dbusx/dbus.go:250 +0x3d
github.com/joshuar/go-hass-agent/internal/linux.(*SensorWorker).Updates(0xc000716270, {0x11b9198, 0xc00071c2d0})
    /home/whitelynx/Development/Other/go-hass-agent/internal/linux/worker.go:137 +0x10d
github.com/joshuar/go-hass-agent/internal/agent.runWorkers({0x11b9160, 0xc00044d080}, {0x11b8f30, 0xc0005322e0}, {0x11b8f68, 0xc0005322d0})
    /home/whitelynx/Development/Other/go-hass-agent/internal/agent/runners.go:58 +0x3f1
github.com/joshuar/go-hass-agent/internal/agent.(*Agent).Run.func2.2()
    /home/whitelynx/Development/Other/go-hass-agent/internal/agent/agent.go:104 +0x65
created by github.com/joshuar/go-hass-agent/internal/agent.(*Agent).Run.func2 in goroutine 29
    /home/whitelynx/Development/Other/go-hass-agent/internal/agent/agent.go:102 +0x19a

Desktop:

Additional context I encountered this because there's no go-hass-agent package on Void Linux, and when building manually, the documentation doesn't mention Geoclue2 being a prerequisite. Even after installing it, I'm unable to get Geoclue2 to actually run, so I'm still blocked by this error. (some of the specifics changed, of course - it now says Launch helper exited with unknown return code 253 instead of The name org.freedesktop.GeoClue2 was not provided by any .service files but the logs otherwise look practically identical)

For use on a desktop, it doesn't make sense to require a location sensor. (related to the first part of #171)

joshuar commented 2 months ago

Firstly thank you for trying out Go Hass Agent and also reporting this issue!

I can see what is the issue here, I recently performed some code clean-up and refactoring that's introduced this bug. Hopefully, commit aeca41062fa3db781ccc241bf272bd34640dd6a0 fixes the crash and commit acac8d74e14f216db3d2ebfe6297114e0365528e adds the functionality to not start a location sensor when not running on a laptop. Would you be able to try checking out the latest source, building and seeing if that fixes the issue for you?

Would it also be useful if the releases contained a binary archive? i.e., just an amd64 binary in a tar.gz? You'd still need to install the additional libraries the agent needs but this might make it easier on distros I don't have a package for?

joshuar commented 2 months ago

Just following up, v.9.4.0 should fix the crash observed here. Also, a location sensor won't be created unless you are running on a laptop.

Please try out the latest version and reply back with the results when you can!

whitelynx commented 2 months ago

I pulled the latest (Updating bfc0c89..2b60928) and it seems to have worked. Thanks for fixing that so quickly!

As far as the location sensor being created, I am on a laptop, but I use it as a desktop - it's always plugged into an external keyboard, mouse, and monitor, and I don't move it. It would still be nice to be able shut off the location sensor, but I think #171 covers that. :)