Fixed #31166 -- Used "raise from" when raising ImproperlyConfigured exceptions in django.urls.resolvers.
This change sets the __cause__ attribute to raised exceptions and makes small cleanups in error messages.
This commit is contained in:
parent
73563183c2
commit
bf3e8227a9
|
@ -190,7 +190,7 @@ class RegexPattern(CheckURLMixin):
|
|||
except re.error as e:
|
||||
raise ImproperlyConfigured(
|
||||
'"%s" is not a valid regular expression: %s' % (regex, e)
|
||||
)
|
||||
) from e
|
||||
|
||||
def __str__(self):
|
||||
return str(self._regex)
|
||||
|
@ -234,8 +234,9 @@ def _route_to_regex(route, is_endpoint=False):
|
|||
converter = get_converter(raw_converter)
|
||||
except KeyError as e:
|
||||
raise ImproperlyConfigured(
|
||||
"URL route '%s' uses invalid converter %s." % (original_route, e)
|
||||
)
|
||||
'URL route %r uses invalid converter %r.'
|
||||
% (original_route, raw_converter)
|
||||
) from e
|
||||
converters[parameter] = converter
|
||||
parts.append('(?P<' + parameter + '>' + converter.regex + ')')
|
||||
if is_endpoint:
|
||||
|
@ -588,13 +589,13 @@ class URLResolver:
|
|||
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
|
||||
try:
|
||||
iter(patterns)
|
||||
except TypeError:
|
||||
except TypeError as e:
|
||||
msg = (
|
||||
"The included URLconf '{name}' does not appear to have any "
|
||||
"patterns in it. If you see valid patterns in the file then "
|
||||
"the issue is probably caused by a circular import."
|
||||
)
|
||||
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
|
||||
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
|
||||
return patterns
|
||||
|
||||
def resolve_error_handler(self, view_type):
|
||||
|
|
Loading…
Reference in New Issue