changeset 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
files tincan.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tincan.py	Thu May 16 18:42:22 2019 -0700
+++ b/tincan.py	Thu May 16 19:58:02 2019 -0700
@@ -397,8 +397,13 @@
         if self._header.template is not None:
             if not self._header.template.endswith(_TEXTEN):
                 raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN))
-            tpath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._header.template)))
-            tfile = TemplateFile(tpath)
+            try:
+                tpath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._header.template)))
+                tfile = TemplateFile(tpath)
+            except OSError as e:
+                raise TinCanError("{0}: invalid #template: {1!s}".format(self._urlpath, e)) from e
+            except IndexError as e:
+                raise TinCanError("{0}: invalid #template".format(self._urlpath)) from e
             self._body = self._tclass(source=tfile.body)
         else:
             self._body = self._tclass(source=self._template.body)
@@ -470,7 +475,7 @@
             mod =  importlib.util.module_from_spec(spec)
             spec.loader.exec_module(mod)
         except Exception as e:
-            raise TinCanError("{0}: error importing".format(pycpath)) from e
+            raise TinCanError("{0}: error importing: {1!s}".format(pycpath, e)) from e
         # Locate a suitable class
         self._class = None
         for i in dir(mod):