You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to propose to add the original exception as the cause of the ImproperlyConfigured exception that's raised when an environment variable is missing using raise ... from ...:
error_msg="Set the {} environment variable".format(var)
raiseImproperlyConfigured(error_msg)
Note: Since it's a two-line change, I've opened #361 to introduce this change. I know that the proposal hasn't been discussed yet, but I figured not a lot of work is lost if it's rejected.
Background
The main difference is that this will mark the original KeyError as the explicit cause of the ImproperlyConfigered, instead of marking the ImproperlyConfigured as another exception that "happened to happen" during the handling of the KeyError. (A better explanation is given by Martijn Pieters here).
Differences for end-users
The most notable difference is the output. The proposed change would change the traceback output to:
Traceback (most recent call last):
(...)
KeyError: 'missing_key'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
(...)
environ.compat.ImproperlyConfigured: Set the missing_key environment variable
instead of
Traceback (most recent call last):
(...)
KeyError: 'missing_key'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
(...)
environ.compat.ImproperlyConfigured: Set the missing_key environment variable
Notice that the middle line that indicates the relationship between the two exceptions has changed.
Additionally, the original exception will now be attached to the ImproperlyConfigured exception under the __cause__ attribute instead of the __context__ attribute.
The text was updated successfully, but these errors were encountered:
I'd like to propose to add the original exception as the cause of the
ImproperlyConfigured
exception that's raised when an environment variable is missing usingraise ... from ...
:The original:
django-environ/environ/environ.py
Lines 366 to 371 in 509cf77
Note: Since it's a two-line change, I've opened #361 to introduce this change. I know that the proposal hasn't been discussed yet, but I figured not a lot of work is lost if it's rejected.
Background
The main difference is that this will mark the original
KeyError
as the explicit cause of theImproperlyConfigered
, instead of marking theImproperlyConfigured
as another exception that "happened to happen" during the handling of theKeyError
. (A better explanation is given by Martijn Pieters here).Differences for end-users
The most notable difference is the output. The proposed change would change the traceback output to:
instead of
Notice that the middle line that indicates the relationship between the two exceptions has changed.
Additionally, the original exception will now be attached to the
ImproperlyConfigured
exception under the__cause__
attribute instead of the__context__
attribute.The text was updated successfully, but these errors were encountered: