Mercurial > piecrust2
changeset 1177:e307f61d7034
rendering: Improve error handling.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 21 May 2020 22:05:30 -0700 |
parents | 28c388fc18b2 |
children | 31e8ee0bf5b2 |
files | piecrust/page.py |
diffstat | 1 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/page.py Thu May 21 22:04:35 2020 -0700 +++ b/piecrust/page.py Thu May 21 22:05:30 2020 -0700 @@ -258,7 +258,7 @@ with source.app.env.stats.timerScope('PageLoad'): return _do_load_page(source, content_item) except Exception as e: - logger.exception("Error loading page: %s" % content_item.spec) + logger.exception("Error loading page '%s': %s" % (content_item.spec, e)) raise PageLoadingError(content_item.spec) from e @@ -270,14 +270,18 @@ cache_path = hashlib.md5(cache_token.encode('utf8')).hexdigest() + '.json' page_time = source.getItemMtime(content_item) if cache.isValid(cache_path, page_time): - cache_data = json.loads( - cache.read(cache_path), - object_pairs_hook=collections.OrderedDict) - config = PageConfiguration( - values=cache_data['config'], - validate=False) - content = json_load_segments(cache_data['content']) - return config, content, True + try: + cache_data = json.loads( + cache.read(cache_path), + object_pairs_hook=collections.OrderedDict) + config = PageConfiguration( + values=cache_data['config'], + validate=False) + content = json_load_segments(cache_data['content']) + return config, content, True + except Exception as e: + logger.exception("Error loading cache for '%s': %s" % (content_item.spec, e)) + logger.exception("Falling back on actual page.") # Nope, load the page from the source file. logger.debug("Loading page configuration from: %s" % content_item.spec)