Skip to content

Commit

Permalink
Added new exception when bundle is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
aouaki committed Aug 13, 2016
1 parent dbdcf19 commit 5c1686c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from webpack_loader.exceptions import (
WebpackError,
WebpackLoaderBadStatsError,
WebpackLoaderTimeoutError
WebpackLoaderTimeoutError,
WebpackBundleLookupError
)
from webpack_loader.utils import get_loader

Expand Down Expand Up @@ -158,7 +159,7 @@ def test_missing_bundle(self):
self.compile_bundles('webpack.config.simple.js')
try:
get_loader(DEFAULT_CONFIG).get_bundle(missing_bundle_name)
except WebpackError as e:
except WebpackBundleLookupError as e:
self.assertIn('Cannot resolve bundle {}'.format(missing_bundle_name), str(e))

def test_missing_stats_file(self):
Expand Down
11 changes: 10 additions & 1 deletion webpack_loader/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
__all__ = ('WebpackError', 'WebpackLoaderBadStatsError')
__all__ = (
'WebpackError',
'WebpackLoaderBadStatsError',
'WebpackLoaderTimeoutError',
'WebpackBundleLookupError'
)


class WebpackError(Exception):
Expand All @@ -11,3 +16,7 @@ class WebpackLoaderBadStatsError(Exception):

class WebpackLoaderTimeoutError(Exception):
pass


class WebpackBundleLookupError(Exception):
pass
13 changes: 6 additions & 7 deletions webpack_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from .exceptions import (
WebpackError,
WebpackLoaderBadStatsError,
WebpackLoaderTimeoutError
WebpackLoaderTimeoutError,
WebpackBundleLookupError
)
from .config import load_config

Expand Down Expand Up @@ -76,12 +77,10 @@ def get_bundle(self, bundle_name):
)

if assets.get('status') == 'done':
chunks = assets['chunks']
try:
bundle_chunks = chunks[bundle_name]
except KeyError:
raise WebpackError('Cannot resolve bundle {0}.'.format(bundle_name))
return self.filter_chunks(bundle_chunks)
chunks = assets['chunks'].get(bundle_name, None)
if chunks is None:
raise WebpackBundleLookupError('Cannot resolve bundle {0}.'.format(bundle_name))
return self.filter_chunks(chunks)

elif assets.get('status') == 'error':
if 'file' not in assets:
Expand Down

0 comments on commit 5c1686c

Please sign in to comment.