[vala/staging: 1/2] vala: Issue a warning on DBus methods which are not throwing an Error
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/2] vala: Issue a warning on DBus methods which are not throwing an Error
- Date: Sun, 11 Feb 2018 20:23:24 +0000 (UTC)
commit 07c8865d0d86d1b73e9e4247e998ec2d03d0ebf2
Author: Dr. Michael Lauer <mickey vanille-media de>
Date: Sun Feb 11 17:18:35 2018 +0100
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
tests/Makefile.am | 1 +
tests/dbus/bug792277.vala | 21 +++++++++++++++++++++
vala/valamethod.vala | 29 +++++++++++++++++++++++++++++
3 files changed, 51 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..4c8c08e
--- /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 8af2f66..133bca5 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]