[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kate] kate/plugins/pate/src/kate: Catch and display any unhandled exceptions raised by actions.
From:       Shaheed Haque <srhaque () theiet ! org>
Date:       2012-09-22 19:01:39
Message-ID: 20120922190139.35055A6094 () git ! kde ! org
[Download RAW message or body]

Git commit f74240807340807fe88df7d514f88272f4074ecf by Shaheed Haque.
Committed on 22/09/2012 at 20:58.
Pushed by shaheed into branch 'master'.

Catch and display any unhandled exceptions raised by actions.

Provide a common fallback GUI display for unhandled exceptions from
actions.

M  +15   -0    kate/plugins/pate/src/kate/__init__.py

http://commits.kde.org/kate/f74240807340807fe88df7d514f88272f4074ecf

diff --git a/kate/plugins/pate/src/kate/__init__.py b/kate/plugins/pate/src/kate/__init__.py
index b4f37ae..b337d67 100644
--- a/kate/plugins/pate/src/kate/__init__.py
+++ b/kate/plugins/pate/src/kate/__init__.py
@@ -28,6 +28,8 @@ import traceback
 import functools
 import pydoc
 from inspect import getmembers, isfunction
+from PyKDE4.kdecore import i18n
+from PyKDE4.kdeui import KMessageBox
 
 import pate
 import kate.gui
@@ -276,6 +278,18 @@ def action(text, icon=None, shortcut=None, menu=None):
     NOTE: Kate may need to be restarted for this decorator to take effect, or
     to remove all traces of the plugin on removal.
     '''
+    class catchAllHandler(object):
+        '''Standard error handling for plugin actions.'''
+        def __init__(self, f):
+            self.f = f
+
+        def __call__(self):
+            try:
+                self.f()
+            except Exception, e:
+                txt = "".join(traceback.format_exception(*sys.exc_info()))
+                KMessageBox.error(None, txt, i18n("Error in action '{}'").format(self.f.__name__))
+
     def decorator(func):
         a = kdeui.KAction(text, None)
         if shortcut is not None:
@@ -286,6 +300,7 @@ def action(text, icon=None, shortcut=None, menu=None):
         if icon is not None:
             a.setIcon(kdeui.KIcon(icon))
         a.menu = menu
+        func = catchAllHandler(func)
         a.connect(a, QtCore.SIGNAL('triggered()'), func)
         # delay till everything has been initialised
         action.actions.add(a)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic