Commit cb631f83 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Display proper traceback and source code if an error occurred on 'exec'.

The initial 'exec' traceback was not passed when raising ImportError (following
PEP-302), thus it displayed traceback in component_package instead of the actual
location of the error. Also, Caching source code retrieved from traceback/(i)pdb
(through get_source()) was done after the actual 'exec', whereas it should have
always been *before* obviously...

Steps to reproduce:
  1/ Create and validate a Test Component A importing another Component B.
  2/ Invalidate Component B or add a typo not handled by pylint (because of exceptions).
parent d612e1ba
......@@ -347,6 +347,13 @@ class ComponentDynamicPackage(ModuleType):
# This must be set for imports at least (see PEP 302)
module.__file__ = '<' + relative_url + '>'
# Only useful for get_source(), do it before exec'ing the source code
# so that the source code is properly display in case of error
module.__loader__ = self
module.__path__ = []
module.__name__ = module_fullname
self.__fullname_source_code_dict[module_fullname] = source_code_str
try:
# XXX: Any loading from ZODB while exec'ing the source code will result
# in a deadlock
......@@ -357,13 +364,9 @@ class ComponentDynamicPackage(ModuleType):
if module_fullname_alias:
del sys.modules[module_fullname_alias]
raise ImportError("%s: cannot load Component %s (%s)" % (fullname,
name,
error))
module.__path__ = []
module.__loader__ = self
module.__name__ = module_fullname
raise ImportError(
"%s: cannot load Component %s (%s)" % (fullname, name, error)), \
None, sys.exc_info()[2]
# Add the newly created module to the Version package and add it as an
# alias to the top-level package as well
......@@ -388,9 +391,6 @@ class ComponentDynamicPackage(ModuleType):
module_cache_set.add(module)
# Only useful for get_source()
self.__fullname_source_code_dict[module_fullname] = source_code_str
return module
finally:
# load_module() can be called outside of import machinery, for example
......
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