Commit fc3d26ff authored by Garrett Regier's avatar Garrett Regier

Do not reveal Python loader internals in tracebacks

This adds format_plugin_exception() which
removes all internal Python frames from the traceback.
parent e42c5820
......@@ -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__",
"") == 0);
goto_error_if_failed (PyModule_AddObject (module, "__builtins__",
builtins_module) == 0);
goto_error_if_failed (PyModule_AddObject (module, "ALREADY_INITIALIZED",
......@@ -58,6 +58,19 @@ class Hooks(object):
# This is implemented by the plugin loader
raise NotImplementedError('Hooks.failed()')
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):
result = getattr(self, name)(*args)
......@@ -99,7 +112,7 @@ class Hooks(object):
module = None
self.failed("Error importing plugin '%s':\n%s" %
(module_name, traceback.format_exc()))
(module_name, self.format_plugin_exception()))
self.__extension_cache[module] = {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment