stefano-m / lua-dbus_proxy

Simple API around GLib's GIO:GDBusProxy built on top of lgi
https://stefano-m.github.io/lua-dbus_proxy/
Apache License 2.0
17 stars 7 forks source link

added error-handling for call_sync #2

Closed terminar closed 5 years ago

terminar commented 5 years ago

As mentioned at https://github.com/pavouk/lgi/blob/master/docs/guide.md#21-calling-functions-and-methods: Functions reporting errors through GError ** as last argument use Lua standard error reporting - they typically return boolean value indicating either success or failure, and if failure occurs, following return values represent error message and error code.

codecov[bot] commented 5 years ago

Codecov Report

Merging #2 into master will increase coverage by 1.43%. The diff coverage is 100%.

@@            Coverage Diff             @@
##           master       #2      +/-   ##
==========================================
+ Coverage   87.93%   89.36%   +1.43%     
==========================================
  Files           5        5              
  Lines         232      235       +3     
==========================================
+ Hits          204      210       +6     
+ Misses         28       25       -3
stefano-m commented 5 years ago

Thanks for your interest in this library and your PR! I am going to leave a couple of comments in the review.

terminar commented 5 years ago

I'll check how I can extend the documentation, give an example and take a look at introspect

terminar commented 5 years ago

I've found another situation with call_sync(). Currently, it only returns only one argument but some dbus Methods may return several arguments. I have to check that and will give feedback here. Also, maybe I made a mistake,

return nil, err

is wrong, it should be

return out, err

because "out" can also be a boolean - false (which is also "not true").

terminar commented 5 years ago

OK, return out, err is fixed. I can't confirm a problem with multiple return results yet, then this PR is finished from my side.

stefano-m commented 5 years ago

Merged 4ad61bd

terminar commented 5 years ago

Sorry for the late answer, I was out of office.

I'm not working on a NetworkManager library, I am just using the DBus Proxy with the NetworkManager via DBus in an application.

I think it's possible to provide some (small) examples how the NetworkManager can be used. Maybe an "example" folder in the lua-dbus_proxy project is an idea for such stuff?

But I did a small wrapper for the dbus_proxy using metatables to use it like this:

Getting the hostname via NetworkManager:

        local dbus = require 'dbus'
        local NetworkManager = dbus.org.freedesktop.NetworkManager
        local settings =NetworkManager("$/Settings","$.Settings")
        return settings.Hostname

Getting all units from Systems:

    local dbus = require 'dbus'
    local systemd = dbus.org.freedesktop.systemd1
    local manager = systemd(nil,"$.Manager")
    return manager:ListUnits()

So I have to rewrite the examples or you are not interested in the wrapper-code. It was more readable for me and it uses $ as wildcard for the current "path". For the path, it contains the needed slashes, for the interface, it contains the needed dots.

stefano-m commented 5 years ago

@terminar, that looks interesting! Why don't you open a new issue to talk about this?