Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha-pgp@silbe.org>2015-11-02 09:55:00 (GMT)
committer Sascha Silbe <sascha-pgp@silbe.org>2015-11-02 09:55:00 (GMT)
commitd22ae3e8c80e828cfa2dff04efb73e2c1eda79ba (patch)
treeddedac219129b1350a13f0c9636554407c149592
parent5dc851866520362f31fb498fbe0d03166f68dae4 (diff)
Log all exceptions for D-Bus methods
For easier debugging, log any exception we pass through to the caller.
-rw-r--r--gdatastore/datastore.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/gdatastore/datastore.py b/gdatastore/datastore.py
index 345ca77..cdd1d3c 100644
--- a/gdatastore/datastore.py
+++ b/gdatastore/datastore.py
@@ -17,6 +17,7 @@ Gdatastore D-Bus service API
"""
import ast
+import functools
import hashlib
import logging
import os
@@ -78,6 +79,17 @@ class GitError(DataStoreError):
return self.__unicode__()
+def method_log_exception(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ try:
+ return func(*args, **kwargs)
+ except:
+ logging.exception('Exception encountered:')
+ raise
+ return wrapper
+
+
class DBusApiNativeV1(dbus.service.Object):
"""Native gdatastore D-Bus API
"""
@@ -115,6 +127,7 @@ class DBusApiNativeV1(dbus.service.Object):
# pylint: disable-msg=C0103
pass
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='a{sv}ay', out_signature='ss',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -132,6 +145,7 @@ class DBusApiNativeV1(dbus.service.Object):
async_cb=async_cb,
async_err_cb=async_err_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='a{sv}h', out_signature='ss',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -152,6 +166,7 @@ class DBusApiNativeV1(dbus.service.Object):
async_cb=async_cb,
async_err_cb=async_err_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ssa{sv}ay', out_signature='s',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -176,6 +191,7 @@ class DBusApiNativeV1(dbus.service.Object):
async_cb=success_cb,
async_err_cb=async_err_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ssa{sv}h', out_signature='s',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -206,6 +222,7 @@ class DBusApiNativeV1(dbus.service.Object):
async_cb=success_cb,
async_err_cb=async_err_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ssa{sv}', out_signature='',
byte_arrays=True)
@@ -216,18 +233,21 @@ class DBusApiNativeV1(dbus.service.Object):
object_id = (tree_id, version_id)
self._internal_api.change_metadata(object_id, metadata)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ss', out_signature='')
def delete(self, tree_id, version_id):
object_id = (tree_id, version_id)
self._internal_api.delete(object_id)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='a{sv}a{sv}', out_signature='aa{sv}u',
byte_arrays=True)
def find(self, query_dict, options):
return self._internal_api.find(query_dict, options)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ss', out_signature='ay',
sender_keyword='sender')
@@ -235,6 +255,7 @@ class DBusApiNativeV1(dbus.service.Object):
object_id = (tree_id, version_id)
return self._internal_api.get_data_path(object_id, sender=sender)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ss', out_signature='h',
sender_keyword='sender')
@@ -243,18 +264,21 @@ class DBusApiNativeV1(dbus.service.Object):
path = self._internal_api.get_data_path(object_id, sender=sender)
return os.open(path, os.O_RDONLY)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='ss', out_signature='a{sv}')
def get_metadata(self, tree_id, version_id):
object_id = (tree_id, version_id)
return self._internal_api.get_properties(object_id)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='a{sv}sa{sv}', out_signature='aa{sv}u',
byte_arrays=True)
def text_search(self, query_dict, query_string, options):
return self._internal_api.find(query_dict, options, query_string)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='sssa{sv}ay', out_signature='ss',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -274,6 +298,7 @@ class DBusApiNativeV1(dbus.service.Object):
async_cb=async_cb,
async_err_cb=async_err_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_NATIVE_V1,
in_signature='sssa{sv}s', out_signature='ss',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -330,6 +355,7 @@ class DBusApiSugarV2(dbus.service.Object):
self._internal_api.add_callback('delete', self.__delete_cb)
self._internal_api.add_callback('save', self.__save_cb)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='a{sv}sb', out_signature='s',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -350,6 +376,7 @@ class DBusApiSugarV2(dbus.service.Object):
# pylint: disable-msg=C0103
pass
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='sa{sv}sb', out_signature='',
async_callbacks=('async_cb', 'async_err_cb'),
@@ -380,6 +407,7 @@ class DBusApiSugarV2(dbus.service.Object):
# pylint: disable-msg=C0103
pass
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='a{sv}as', out_signature='aa{sv}u')
def find(self, query, properties):
@@ -404,6 +432,7 @@ class DBusApiSugarV2(dbus.service.Object):
return results, count
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='s', out_signature='s',
sender_keyword='sender')
@@ -415,6 +444,7 @@ class DBusApiSugarV2(dbus.service.Object):
object_id = (uid, latest_versions[0]['version_id'])
return self._internal_api.get_data_path(object_id, sender=sender)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='s', out_signature='a{sv}')
def get_properties(self, uid):
@@ -426,11 +456,13 @@ class DBusApiSugarV2(dbus.service.Object):
del latest_versions[0]['version_id']
return latest_versions[0]
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='sa{sv}', out_signature='as')
def get_uniquevaluesfor(self, propertyname, query=None):
return self._internal_api.find_unique_values(query, propertyname)
+ @method_log_exception
@dbus.service.method(DBUS_INTERFACE_SUGAR_V2,
in_signature='s', out_signature='')
def delete(self, uid):