Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fail loudly on AttributeError

  • Loading branch information...
commit 0dd900736c078cb34d03d8a434bc73ec2dae8801 1 parent 7061627
@matthewwithanm matthewwithanm authored anttihirvonen committed
Showing with 16 additions and 4 deletions.
  1. +9 −4 compressor/base.py
  2. +7 −0 compressor/exceptions.py
View
13 compressor/base.py
@@ -13,7 +13,8 @@
from compressor.cache import get_hexdigest, get_mtime
from compressor.conf import settings
-from compressor.exceptions import CompressorError, UncompressableFileError
+from compressor.exceptions import (CompressorError, UncompressableFileError,
+ FilterDoesNotExist)
from compressor.filters import CompilerFilter
from compressor.storage import default_storage, compressor_file_storage
from compressor.signals import post_compress
@@ -209,12 +210,16 @@ def precompile(self, content, kind=None, elem=None, filename=None, **kwargs):
else:
mod_name, cls_name = get_mod_func(filter_or_command)
try:
- precompiler_class = getattr(import_module(mod_name),
- cls_name)
- except (ImportError, AttributeError):
+ mod = import_module(mod_name)
+ except ImportError:
return True, CompilerFilter(content, filter_type=self.type,
command=filter_or_command, filename=filename).input(
**kwargs)
+ try:
+ precompiler_class = getattr(mod, cls_name)
+ except AttributeError:
+ raise FilterDoesNotExist('Could not find "%s".' %
+ filter_or_command)
else:
return True, precompiler_class(content,
filter_type=self.type, filename=filename).input(
View
7 compressor/exceptions.py
@@ -31,3 +31,10 @@ class OfflineGenerationError(Exception):
Offline compression generation related exceptions
"""
pass
+
+
+class FilterDoesNotExist(Exception):
+ """
+ Raised when a filter class cannot be found.
+ """
+ pass
Please sign in to comment.
Something went wrong with that request. Please try again.