3333# file paths to allow watching them in the future.
3434_error_files = []
3535_exception = None
36+ # Exception raised while loading the URLConf.
37+ _url_module_exception = None
3638
3739try :
3840 import termios
@@ -62,7 +64,7 @@ def wrapper(*args, **kwargs):
6264 global _exception
6365 try :
6466 fn (* args , ** kwargs )
65- except Exception :
67+ except Exception as e :
6668 _exception = sys .exc_info ()
6769
6870 et , ev , tb = _exception
@@ -75,8 +77,10 @@ def wrapper(*args, **kwargs):
7577
7678 if filename not in _error_files :
7779 _error_files .append (filename )
80+ if _url_module_exception is not None :
81+ raise e from _url_module_exception
7882
79- raise
83+ raise e
8084
8185 return wrapper
8286
@@ -339,6 +343,7 @@ def wait_for_apps_ready(self, app_reg, django_main_thread):
339343 return False
340344
341345 def run (self , django_main_thread ):
346+ global _url_module_exception
342347 logger .debug ("Waiting for apps ready_event." )
343348 self .wait_for_apps_ready (apps , django_main_thread )
344349 from django .urls import get_resolver
@@ -347,10 +352,10 @@ def run(self, django_main_thread):
347352 # reloader starts by accessing the urlconf_module property.
348353 try :
349354 get_resolver ().urlconf_module
350- except Exception :
355+ except Exception as e :
351356 # Loading the urlconf can result in errors during development.
352- # If this occurs then swallow the error and continue.
353- pass
357+ # If this occurs then store the error and continue.
358+ _url_module_exception = e
354359 logger .debug ("Apps ready_event triggered. Sending autoreload_started signal." )
355360 autoreload_started .send (sender = self )
356361 self .run_loop ()
0 commit comments