GNOME Bugzilla – Bug 792277
valac should not allow DBus interface methods not throwing IOError
Last modified: 2018-02-12 09:16:54 UTC
This code [DBus (name = "com.github.lmberg.example")] public interface Test : Object { public abstract bool ping (); } compiles without any complaints. However, DBus interface methods should not be declared without "throws IOError". Otherwise, no error would be thrown if Test.ping() could not be found on the bus, for example. (GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod) From https://wiki.gnome.org/Projects/Vala/DBusServerSample : "The methods of the client interface must be defined with throws IOError. "
Thanks for your bug report. I agree that it is unfortunate, since it hides potential CRITICAL run-time errors making the program abort unexpectedly. We can't make it a compile error immediately though, since that would break a lot of existing code unnecessarily. I propose to emit a warning like "WARNING: Declaring a DBus method without throwing at least IOError is deprecated." and changing this to a hard error eventually. I'll work on a patch (if no-one else wants to).
Created attachment 368211 [details] [review] Report a deprecation warning when a DBus method does not throw at least DBusError and IOError Here's a patch that might do the right thing. Would anyone of the core developers please review and give feedback?
Created attachment 368229 [details] [review] Report a deprecation warning when a DBus method does not throw at least DBusError and IOError 2nd try, this time the logic is put into vala, as opposed to the codegen. Should also adhere to code style guide now.
Created attachment 368231 [details] [review] Report a deprecation warning when a DBus method does not throw at least DBusError and IOError
Created attachment 368233 [details] [review] vala: DBus methods are recommended to throw at least DBusError or IOError This issues a warning now and will be turned into an error at some point.
Thanks for polishing my patch! I have one question though… you changed the semantics into a "IOError _or_ DBusError". To my knowledge, Vala error domains do not form a hierarchy, or do they? I was thinking that IOError covers other type of errors than DBusError, hence a proper DBus method would be required to throw both.
Created attachment 368235 [details] [review] vala: Issue a warning on DBus methods which are not throwing an Error It is recommended to throw "GLib.Error" or "GLib.DBusError, GLib.IOError". This will be turned into an error at some point.
Attachment 368235 [details] pushed as 07c8865 - vala: Issue a warning on DBus methods which are not throwing an Error