dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

Forgetting SignalContext arg in dbus_interface signals results a in cryptic error message #247

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @Spider on Jan 7, 2022, 17:23

error[E0599]: no method named `connection` found for reference `&str` in the current scope
   --> mocklogger/src/lib.rs:112:1
    |
112 | #[dbus_interface(name = "com.example.test")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&str`
    |
    = note: this error originates in the attribute macro `dbus_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `path` found for reference `&str` in the current scope
   --> mocklogger/src/lib.rs:112:1
    |
112 | #[dbus_interface(name = "com.example.test")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&str`
    |
    = note: this error originates in the attribute macro `dbus_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

This error message means that I forgot to add the SignalContext to a signal.

Could this perhaps be made to cause a bit of a better compile time error, perhaps something that at least points me to the name of the signal, or something such, as right now I had to comment out the entire file and start manually comment-bisecting the code to figure out what was wrong.

zeenix commented 2 years ago

Could this perhaps be made to cause a bit of a better compile time error, perhaps something that at least points me to the name of the signal, or something such, as right now I had to comment out the entire file and start manually comment-bisecting the code to figure out what was wrong.

Unfortunately the macro has no insight on the actual types so I don't know how this can be achieved apart from ensuring there is at least 1 arg.

zeenix commented 2 years ago

btw, what you get right now is a compile time error, just not a nice and very helpful one. I'm going to close this as I don't see a way to solve this but if you know, please do reopen with the proposed solution as it would be awesome so fix this.

Many thanks for reporting, still. :thumbsup:

zeenix commented 2 years ago

In GitLab by @Spider on Jan 7, 2022, 18:28

True, maybe I should make a signal that takes an argument that has "connection" and "path" as methods and see if things explode drastically....

Anyhow, crappy that the error can't be improved, and crappy that there's no way to simplify this, cause the previous API at least was neater and cut some of the horrid looking and newbie-scaring cruft from the method declarations.

Anyhow, I can't have it all, thanks for you work here, and do keep this closed.

zeenix commented 2 years ago

the previous API at least was neater

There were reasons to change this API. For example, you no longer need a reference to the Interface instance to be able to emit signals.