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

The MessageHandler should not return null but throw a DBusException #1

Closed
swiesend opened this issue Aug 7, 2020 · 1 comment
Closed

Comments

@swiesend
Copy link

swiesend commented Aug 7, 2020

My new MessageHandler avoids returning null on my 2.0.0 branch as this only leads to problems, if the case is not handled properly.

public Object[] send(String service, String path, String iface, String method, String signature, Object... args) {
try {
org.freedesktop.dbus.messages.Message message = new MethodCall(
service,
path,
iface,
method, (byte) 0, signature, args);
connection.sendMessage(message);
org.freedesktop.dbus.messages.Message response = ((MethodCall) message).getReply(2000L);
log.trace(response.toString());
if (response instanceof org.freedesktop.dbus.errors.Error) {
throw new DBusException(response.getName() + ": " + response.getParameters()[0]);
}
Object[] parameters = response.getParameters();
log.debug(Arrays.deepToString(parameters));
return parameters;
} catch (DBusException e) {
log.error(e.toString(), e.getCause());
}
return null;
}

see: https://github.com/swiesend/secret-service/blob/c7399ea1f2d6031158a64a0459a066a35c7f9cbf/src/main/java/org/freedesktop/secret/handlers/MessageHandler.java#L34-L75

see also: swiesend/secret-service#6

@purejava
Copy link
Owner

purejava commented Aug 9, 2020

Thanks for pointing me to the upcoming new release with the improved MessageHandler. It‘s good to have a DBusException instead of returning null in case of MessageHandler having problems sending a message via D-Bus. This will add good robustness to the library for cases where the whole D-Bus back-end fails.
I‘ll adopt your changes when they are released.

Anyway, kdewallet does not have the same challenges secret-service has concerning the handling of org.freedesktop.Secret.Errors within MessageHandler, as they just do not exist in the wallet / KDE context.

Cheers!

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

2 participants