Raise errors when an uncompressable file is encountred during development (just as the docs claim).

This commit is contained in:
Jaap Roes
2011-04-14 01:55:13 +08:00
committed by Jannis Leidel
parent ce924359a5
commit 1b43826ef7
2 changed files with 13 additions and 5 deletions

View File

@@ -173,18 +173,28 @@ class Compressor(object):
else: else:
# or just doing nothing, when neither # or just doing nothing, when neither
# compression nor compilation is enabled # compression nor compilation is enabled
return self.content content = self.concat
# Shortcurcuit in case the content is empty. # Shortcurcuit in case the content is empty.
if not content: if not content:
return '' return ''
# Then check for the appropriate output method and call it # Then check for the appropriate output method and call it
output_func = getattr(self, "output_%s" % mode, None) output_func = getattr(self, "output_%s" % mode, None)
if not settings.COMPRESS_ENABLED:
# In order to raise errors about uncompressable files we still
# need to fake output.
output_func = self.output_original
if callable(output_func): if callable(output_func):
return output_func(mode, content, forced) return output_func(mode, content, forced)
# Total failure, raise a general exception # Total failure, raise a general exception
raise CompressorError( raise CompressorError(
"Couldn't find output method for mode '%s'" % mode) "Couldn't find output method for mode '%s'" % mode)
def output_original(self, mode, content, forced=False):
'''
Essentially a do nothing output method.
'''
return self.content.strip()
def output_file(self, mode, content, forced=False): def output_file(self, mode, content, forced=False):
""" """
The output method that saves the content to a file and renders The output method that saves the content to a file and renders

View File

@@ -98,11 +98,9 @@ class CompressorNode(template.Node):
if cache_key: if cache_key:
self.cache_set(cache_key, rendered_output) self.cache_set(cache_key, rendered_output)
return rendered_output return rendered_output
except: except Exception, e:
if settings.DEBUG or forced: if settings.DEBUG or forced:
# Be very loud about the exception we just encountered raise e
from traceback import format_exc
raise Exception(format_exc())
# 5. Or don't do anything in production # 5. Or don't do anything in production
return self.nodelist.render(context) return self.nodelist.render(context)