Skip to content

Commit 926f582

Browse files
aouakiowais
authored andcommitted
Added an exception when bundle name is not valid (django-webpack#71)
* Added an exception when bundle name is not valid * Fix error in python2.6 * Added new exception when bundle is missing * Fix python2.6 error
1 parent 8ba71d0 commit 926f582

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

tests/app/tests/test_webpack.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from webpack_loader.exceptions import (
1414
WebpackError,
1515
WebpackLoaderBadStatsError,
16-
WebpackLoaderTimeoutError
16+
WebpackLoaderTimeoutError,
17+
WebpackBundleLookupError
1718
)
1819
from webpack_loader.utils import get_loader
1920

@@ -153,6 +154,14 @@ def test_reporting_errors(self):
153154
except WebpackError as e:
154155
self.assertIn("Cannot resolve module 'the-library-that-did-not-exist'", str(e))
155156

157+
def test_missing_bundle(self):
158+
missing_bundle_name = 'missing_bundle'
159+
self.compile_bundles('webpack.config.simple.js')
160+
try:
161+
get_loader(DEFAULT_CONFIG).get_bundle(missing_bundle_name)
162+
except WebpackBundleLookupError as e:
163+
self.assertIn('Cannot resolve bundle {0}'.format(missing_bundle_name), str(e))
164+
156165
def test_missing_stats_file(self):
157166
stats_file = settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE']
158167
if os.path.exists(stats_file):

webpack_loader/exceptions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
__all__ = ('WebpackError', 'WebpackLoaderBadStatsError')
1+
__all__ = (
2+
'WebpackError',
3+
'WebpackLoaderBadStatsError',
4+
'WebpackLoaderTimeoutError',
5+
'WebpackBundleLookupError'
6+
)
27

38

49
class WebpackError(Exception):
@@ -11,3 +16,7 @@ class WebpackLoaderBadStatsError(Exception):
1116

1217
class WebpackLoaderTimeoutError(Exception):
1318
pass
19+
20+
21+
class WebpackBundleLookupError(Exception):
22+
pass

webpack_loader/loader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from .exceptions import (
88
WebpackError,
99
WebpackLoaderBadStatsError,
10-
WebpackLoaderTimeoutError
10+
WebpackLoaderTimeoutError,
11+
WebpackBundleLookupError
1112
)
1213
from .config import load_config
1314

@@ -76,7 +77,9 @@ def get_bundle(self, bundle_name):
7677
)
7778

7879
if assets.get('status') == 'done':
79-
chunks = assets['chunks'][bundle_name]
80+
chunks = assets['chunks'].get(bundle_name, None)
81+
if chunks is None:
82+
raise WebpackBundleLookupError('Cannot resolve bundle {0}.'.format(bundle_name))
8083
return self.filter_chunks(chunks)
8184

8285
elif assets.get('status') == 'error':

0 commit comments

Comments
 (0)