[vala/staging] vala: DBus methods are recommended to throw at least DBusError or IOError
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: DBus methods are recommended to throw at least DBusError or IOError
- Date: Sun, 11 Feb 2018 17:56:08 +0000 (UTC)
commit 13c5eb638ecd69bedb7c0d676defc8d141aff0d0
Author: Dr. Michael Lauer <mickey vanille-media de>
Date: Sun Feb 11 17:18:35 2018 +0100
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.
https://bugzilla.gnome.org/show_bug.cgi?id=792277
tests/Makefile.am | 1 +
tests/dbus/bug792277.vala | 26 ++++++++++++++++++++++++++
vala/valamethod.vala | 22 ++++++++++++++++++++++
3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b9d57c..decdb14 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 0000000..5644019
--- /dev/null
+++ b/tests/dbus/bug792277.vala
@@ -0,0 +1,26 @@
+[DBus (name = "org.example.IFoo")]
+public interface IFoo : Object {
+ public abstract void method0 () throws IOError;
+ public abstract void method1 () throws DBusError;
+ [DBus (visible = false)]
+ public abstract void method2 () throws Error;
+ [DBus (visible = false)]
+ public abstract void method3 ();
+}
+
+[DBus (name = "org.example.Foo")]
+public class Foo : Object {
+ public void method0 () throws IOError {
+ }
+ public void method1 () throws DBusError {
+ }
+ [DBus (visible = false)]
+ public void method2 () throws Error {
+ }
+ [DBus (visible = false)]
+ public void method3 () {
+ }
+}
+
+void main () {
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 8af2f66..341e86b 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -856,6 +856,28 @@ public class Vala.Method : Subroutine, Callable {
}
}
+ // check that DBus methods at least throw GLib.DBusError or 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_required_error = false;
+ foreach (DataType error_type in get_error_types ()) {
+ if (!(error_type is ErrorType)) {
+ continue;
+ }
+ unowned ErrorDomain? error_domain = ((ErrorType)
error_type).error_domain;
+ string? full_error_domain = (error_domain == null ? null :
error_domain.get_full_name ());
+ if (full_error_domain == "GLib.DBusError" || full_error_domain ==
"GLib.IOError") {
+ throws_required_error = true;
+ break;
+ }
+ }
+ if (!throws_required_error) {
+ Report.warning (source_reference, "DBus methods are recommended to
throw at least `GLib.DBusError' or `GLib.IOError'");
+ }
+ }
+ }
+
if (is_possible_entry_point (context)) {
if (context.entry_point != null) {
error = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]