Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an exception when bundle name is not valid #71

Merged
merged 4 commits into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebpackError is used to represent errors that were raised by webpack itself. This should use a new exception and how about,

chunks = assets['chunks'].get(bundle_name, None)
if chunks is None:
     raise WebpackBundleLookupError("...")

return self.filter_chunks(bundle_chunks)

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