-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
zb: interface
property setters should return fdo::Error
#992
Comments
This is very strange. We've a test case for this and it does use
Hmm.. that test case hasn't changed for a long while since before 4.4.0 so I'm a bit puzzled why you're seeing this. |
Ah, you're looking into setter, not getter methods. Now it makes sense. 😄 |
Yep, getters work for me with |
At first thought, that sounds right but we've to think about whether or not Having said that, I do think it makes sense for consistency. Fortunately, we're current in an API break so this could be fixed w/o caring about backwards-compatibility. I doubt many folks use fallible setters anyway so impact of porting to 5.0 would be minimal and even affected folks can easily port this part.
Sure. PRs welcome. :) |
interface
property setters should return fdo::Error
Seems to work for non- Line 248 in e12129b
I don't really know much about dbus, so I can't really comment on whether anyone actually uses fallible setters. One usecase might be to return an error when setting out-of-range values on numeric properties? A workaround is Err(zbus::Error::FDO(Box::new(zbus::fdo::Error::NotSupported("...".to_owned())))) but that is quite verbose. (I'm wondering what happens with non-fdo errors in that case, though: They can't be returned on the bus, can they? They don't seem to implement
Fair enough :) I doubt I'll be able to do that, however: I'm not at all familiar with developing proc macros. |
Oh, that's very strange. Maybe some inconsistency in the macro then. Should be an easier fix then.
I guess, yeah but then
Most thing I've learnt are by doing them. The beauty of proc macros is that they're just normal Rust code that runs at compile-time. Of course, it's up to you but I'd suggest giving it a try at least, if you've the motivation and time. |
Oh, looks like I already even had the code to make this happen for getters (#313). If we can do it for getters, we can do it for setters too. However, the same question still remains. 🤔 |
I've been trying to follow method dispatch through the zbus/zbus/src/object_server/mod.rs Lines 695 to 698 in b7762fa
i.e. a custom Maybe, if the goal is to minimize allocations as much as possible, there could be an enum DBusError {
FDO(fdo::Error),
Custom(Box<dyn DBusError>),
} which would be used to pass around method results within zbus? Then, even in the error case, EDIT: In fact, this might be basically what you're saying above? |
Good catch. yeah I guess, that's what its doing currently. I think we can change it.
Yeah, but after my comment here, I realised perhaps allocation isn't so bad in this case. |
Good idea though. :) |
Oh, what's actually going is that there's a difference between Lines 845 to 867 in e12129b
So the |
Ah right. I think the issue is that pub enum DispatchResult<'a, T: DBusError> {
/// This interface does not support the given method.
NotFound,
/// Retry with [Interface::call_mut].
///
/// This is equivalent to NotFound if returned by call_mut.
RequiresMut,
/// The method was found and will be completed by running this Future.
Async(Pin<Box<dyn Future<Output = std::result::Result<(), T>> + Send + 'a>>),
} Interestingly, the |
Actually, no. There are two types of errors here. One is the error for the service-side (which should be I'll need to investigate further what's going on but a likely place to look into is the macro code, specifically here. P.S. |
Indeed, boxing all errors might be the easiest approach:
I've been thinking about this a bit more, and I think that would require specialization to work: The following enum DBusError {
FDO(fdo::Error),
Custom(Box<dyn DBusError>),
}
// Accept `fn prop() -> zbus::Result<u32>`
impl From<zbus::Error> for DBusError {
fn from(val: zbus::Error) -> Self {
Self::FDO(fdo::Error::Zbus(val)),
}
}
// Accept `fn prop() -> zbus::fdo::Result<u32>`
impl From<fdo::Error> for DBusError {
fn from(val: fdo::Error) -> Self {
Self::FDO(val),
}
}
// Accept `fn prop() -> std::result::Result<u32, CustomError>`
impl<E: DBusError> From<E> for DBusError {
fn from(val: E) -> Self {
Self::Custom(),
}
} would probably not compile, since I'm not sure that it would be sensible for any of the methods to return the service-side |
The book explains how to write fallible methods and property getters in interfaces at https://dbus2.github.io/zbus/service.html#method-errors.
However, it seems that this is not actually the full picture: Fallible property setters only compile when returning
zbus::Error
, whereaszbus::fdo::Error
produces very opaque error messages like the following:which does not point to the code span that causes the error.
It would be very convenient (and, in my opinion, more consistent) if method setters could also return
zbus::fdo::Error
. In any case, it would be great if the documentation could be updated to mention the expected return type, and if theinterface
examples could be extended to contain a fallible property setter. Maybe it would also be possible to enhance the proc macro such that it yields errors that point to the offending code?Thanks!
This is
zbus = 4.4.0
.The text was updated successfully, but these errors were encountered: