comparison tincan.py @ 16:448fc3d534f8 draft

Improve error reportage.
author David Barts <n5jrn@me.com>
date Thu, 16 May 2019 19:58:02 -0700
parents 560c8fb55e4a
children 8186de188daf
comparison
equal deleted inserted replaced
15:560c8fb55e4a 16:448fc3d534f8
395 self._getclass() 395 self._getclass()
396 # Build body object (#template) 396 # Build body object (#template)
397 if self._header.template is not None: 397 if self._header.template is not None:
398 if not self._header.template.endswith(_TEXTEN): 398 if not self._header.template.endswith(_TEXTEN):
399 raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN)) 399 raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN))
400 tpath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._header.template))) 400 try:
401 tfile = TemplateFile(tpath) 401 tpath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._header.template)))
402 tfile = TemplateFile(tpath)
403 except OSError as e:
404 raise TinCanError("{0}: invalid #template: {1!s}".format(self._urlpath, e)) from e
405 except IndexError as e:
406 raise TinCanError("{0}: invalid #template".format(self._urlpath)) from e
402 self._body = self._tclass(source=tfile.body) 407 self._body = self._tclass(source=tfile.body)
403 else: 408 else:
404 self._body = self._tclass(source=self._template.body) 409 self._body = self._tclass(source=self._template.body)
405 self._body.prepare() 410 self._body.prepare()
406 # If this is an #errors page, register it as such. 411 # If this is an #errors page, register it as such.
468 try: 473 try:
469 spec = importlib.util.spec_from_file_location(_mangle(self._name), pycpath) 474 spec = importlib.util.spec_from_file_location(_mangle(self._name), pycpath)
470 mod = importlib.util.module_from_spec(spec) 475 mod = importlib.util.module_from_spec(spec)
471 spec.loader.exec_module(mod) 476 spec.loader.exec_module(mod)
472 except Exception as e: 477 except Exception as e:
473 raise TinCanError("{0}: error importing".format(pycpath)) from e 478 raise TinCanError("{0}: error importing: {1!s}".format(pycpath, e)) from e
474 # Locate a suitable class 479 # Locate a suitable class
475 self._class = None 480 self._class = None
476 for i in dir(mod): 481 for i in dir(mod):
477 v = getattr(mod, i) 482 v = getattr(mod, i)
478 if isclass(v) and issubclass(v, klass) and v is not klass: 483 if isclass(v) and issubclass(v, klass) and v is not klass: