Skip to content

Commit d06526a

Browse files
committed
Fix exception causes in lookup.py
1 parent 299652e commit d06526a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

mako/lookup.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from mako import exceptions
1313
from mako import util
14+
from mako import compat
1415
from mako.template import Template
1516

1617
try:
@@ -249,7 +250,7 @@ def get_template(self, uri):
249250
return self._check(uri, self._collection[uri])
250251
else:
251252
return self._collection[uri]
252-
except KeyError:
253+
except KeyError as e:
253254
u = re.sub(r"^\/+", "", uri)
254255
for dir_ in self.directories:
255256
# make sure the path seperators are posix - os.altsep is empty
@@ -259,8 +260,12 @@ def get_template(self, uri):
259260
if os.path.isfile(srcfile):
260261
return self._load(srcfile, uri)
261262
else:
262-
raise exceptions.TopLevelLookupException(
263-
"Cant locate template for uri %r" % uri
263+
compat.reraise(
264+
exceptions.TopLevelLookupException,
265+
exceptions.TopLevelLookupException(
266+
"Cant locate template for uri %r" % uri
267+
),
268+
cause=e
264269
)
265270

266271
def adjust_uri(self, uri, relativeto):
@@ -347,10 +352,14 @@ def _check(self, uri, template):
347352
return self._load(template.filename, uri)
348353
else:
349354
return template
350-
except OSError:
355+
except OSError as e:
351356
self._collection.pop(uri, None)
352-
raise exceptions.TemplateLookupException(
353-
"Cant locate template for uri %r" % uri
357+
compat.reraise(
358+
exceptions.TemplateLookupException,
359+
exceptions.TemplateLookupException(
360+
"Cant locate template for uri %r" % uri
361+
),
362+
cause=e
354363
)
355364

356365
def put_string(self, uri, text):

0 commit comments

Comments
 (0)