From: Dr. Michael Lauer Date: Sun, 11 Feb 2018 16:18:35 +0000 (+0100) Subject: vala: Issue a warning on DBus methods which are not throwing an Error X-Git-Tag: 0.39.91~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07c8865d0d86d1b73e9e4247e998ec2d03d0ebf2;p=thirdparty%2Fvala.git 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. https://bugzilla.gnome.org/show_bug.cgi?id=792277 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 7b9d57c53..decdb14e2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -363,6 +363,7 @@ TESTS = \ dbus/bug596862.vala \ dbus/bug602003.test \ dbus/bug782719.test \ + dbus/bug792277.vala \ dbus/rawvariants.test \ gir/bug651773.test \ gir/bug667751.test \ diff --git a/tests/dbus/bug792277.vala b/tests/dbus/bug792277.vala new file mode 100644 index 000000000..4c8c08ec6 --- /dev/null +++ b/tests/dbus/bug792277.vala @@ -0,0 +1,21 @@ +[DBus (name = "org.example.IFoo")] +public interface IFoo : Object { + public abstract void method0 () throws Error; + public abstract void method1 () throws DBusError, IOError; + [DBus (visible = false)] + public abstract void method2 (); +} + +[DBus (name = "org.example.Foo")] +public class Foo : Object { + public void method0 () throws Error { + } + public void method1 () throws DBusError, IOError { + } + [DBus (visible = false)] + public void method2 () { + } +} + +void main () { +} diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 8af2f667a..133bca52e 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -856,6 +856,35 @@ public class Vala.Method : Subroutine, Callable { } } + // check that DBus methods at least throw "GLib.Error" or "GLib.DBusError, GLib.IOError" + if (parent_symbol is ObjectTypeSymbol && parent_symbol.get_attribute ("DBus") != null) { + Attribute? dbus_attr = get_attribute ("DBus"); + if (dbus_attr == null || dbus_attr.get_bool ("visible", true)) { + bool throws_gerror = false; + bool throws_gioerror = false; + bool throws_gdbuserror = false; + foreach (DataType error_type in get_error_types ()) { + if (!(error_type is ErrorType)) { + continue; + } + unowned ErrorDomain? error_domain = ((ErrorType) error_type).error_domain; + if (error_domain == null) { + throws_gerror = true; + break; + } + string? full_error_domain = error_domain.get_full_name (); + if (full_error_domain == "GLib.IOError") { + throws_gioerror = true; + } else if (full_error_domain == "GLib.DBusError") { + throws_gdbuserror = true; + } + } + if (!throws_gerror && !(throws_gioerror && throws_gdbuserror)) { + Report.warning (source_reference, "DBus methods are recommended to throw at least `GLib.Error' or `GLib.DBusError, GLib.IOError'"); + } + } + } + if (is_possible_entry_point (context)) { if (context.entry_point != null) { error = true;