summaryrefslogtreecommitdiff
path: root/loaders
diff options
context:
space:
mode:
authorGarrett Regier <garrettregier@gmail.com>2015-01-20 01:13:45 -0800
committerGarrett Regier <garrettregier@gmail.com>2015-01-20 01:23:07 -0800
commitfc3d26ff0f12c16941e5ff0501b01316d8df8deb (patch)
tree1e4384a9a7e8b7ca73fd99ee70cb97992d21f345 /loaders
parente42c5820852c009582e2c58a0fbcb45daaa8660c (diff)
downloadlibpeas-fc3d26ff0f12c16941e5ff0501b01316d8df8deb.tar.gz
Do not reveal Python loader internals in tracebacks
This adds format_plugin_exception() which removes all internal Python frames from the traceback. https://bugzilla.gnome.org/show_bug.cgi?id=742349
Diffstat (limited to 'loaders')
-rw-r--r--loaders/python/peas-python-internal.c2
-rw-r--r--loaders/python/peas-python-internal.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/loaders/python/peas-python-internal.c b/loaders/python/peas-python-internal.c
index 227c1b5..dca8e61 100644
--- a/loaders/python/peas-python-internal.c
+++ b/loaders/python/peas-python-internal.c
@@ -116,6 +116,8 @@ peas_python_internal_new (gboolean already_initialized)
module = PyModule_New ("libpeas-internal");
goto_error_if_failed (module != NULL);
+ goto_error_if_failed (PyModule_AddStringConstant (module, "__file__",
+ "peas-python-internal.py") == 0);
goto_error_if_failed (PyModule_AddObject (module, "__builtins__",
builtins_module) == 0);
goto_error_if_failed (PyModule_AddObject (module, "ALREADY_INITIALIZED",
diff --git a/loaders/python/peas-python-internal.py b/loaders/python/peas-python-internal.py
index dcffaeb..d14b4d8 100644
--- a/loaders/python/peas-python-internal.py
+++ b/loaders/python/peas-python-internal.py
@@ -58,6 +58,19 @@ class Hooks(object):
# This is implemented by the plugin loader
raise NotImplementedError('Hooks.failed()')
+ @staticmethod
+ def format_plugin_exception():
+ formatted = traceback.format_exception(*sys.exc_info())
+
+ # Remove all mentions of this file
+ for i in range(len(formatted)):
+ if __file__ in formatted[i]:
+ while not formatted[i].startswith('Traceback'):
+ formatted[i] = ''
+ i -= 1
+
+ return ''.join(formatted)
+
def call(self, name, args, return_type):
try:
result = getattr(self, name)(*args)
@@ -99,7 +112,7 @@ class Hooks(object):
except:
module = None
self.failed("Error importing plugin '%s':\n%s" %
- (module_name, traceback.format_exc()))
+ (module_name, self.format_plugin_exception()))
else:
self.__extension_cache[module] = {}