Skip to content

Commit

Permalink
Added an exception when bundle name is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
aouaki committed Aug 13, 2016
1 parent 8ba71d0 commit 757741c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def test_reporting_errors(self):
except WebpackError as e:
self.assertIn("Cannot resolve module 'the-library-that-did-not-exist'", str(e))

def test_missing_bundle(self):
missing_bundle_name = 'missing_bundle'
self.compile_bundles('webpack.config.simple.js')
try:
get_loader(DEFAULT_CONFIG).get_bundle(missing_bundle_name)
except WebpackError as e:
self.assertIn('Cannot resolve bundle {}'.format(missing_bundle_name), str(e))

def test_missing_stats_file(self):
stats_file = settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE']
if os.path.exists(stats_file):
Expand Down
8 changes: 6 additions & 2 deletions webpack_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ def get_bundle(self, bundle_name):
)

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

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

0 comments on commit 757741c

Please sign in to comment.