-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Improve error related end-user experience #333
base: master
Are you sure you want to change the base?
Conversation
This makes it easier to determine what exactly went wrong and thus build better error handling in a later commit. Tests were adapted accordingly to assert that only those specific errors are raised instead of the plain ValueErrors.
Previously and ImproperlyConfigured error was always raised when an invalid default configured for the BooleanValue class. This behavior is unnecessary if the default is never used because the value is marked as environ_required. The check has thus been adapted to ignore invalid defaults in that case.
This introduces a function that wraps django entry points with an error handler so that our own exception can be pretty-printed to an end-user without a large stack-trace. The defined error handler has also been applied to the existing management, wsgi, asgi and fastcgi entry point definitions.
This way, multiple ConfigurationErrors are caught during setup, accumulated and printed all at once
Now Value classes accept a 'help_text' keyword which will get printed when a ValueRetrievalError or ValueProcessingError occurs
Now Value classes accept a 'help_reference' keyword which will get printed when a ValueRetrievalError or ValueProcessingError occurs
The test failed for two reasons. One was me changing the error string in a previous commit which I have adapted the test for now. The other was that django-cache-url changed its behavior. See #332
Codecov Report
@@ Coverage Diff @@
## master #333 +/- ##
==========================================
+ Coverage 89.94% 90.07% +0.12%
==========================================
Files 25 29 +4
Lines 1194 1360 +166
Branches 235 265 +30
==========================================
+ Hits 1074 1225 +151
- Misses 89 102 +13
- Partials 31 33 +2
Continue to review full report at Codecov.
|
Example generators are an addition to the 'Value' classes that allow the error handler to display example values for the failed value. For example if no django secret key is found to be defined in the environment, an example (secure) value for such a secret key can now be generated on the fly and be suggested to the user
fdfa41c
to
e57a9b8
Compare
e57a9b8
to
3b96d16
Compare
The idea behind this PR is valid but in my experienc e, often the traceback is key to identifying the original source of the problem that triggered string of calls into Django libraries that eventually throws an error in a method that is many method calls way down in the trace and oiften the error message does nto provide any clue as to exactly what caused it. |
In my opinion, an end-user who uses an application that was built using django-configurations should in most cases not see an unwieldy traceback, but instead a nicely formatted error detailing what went wrong and what they should do to rectify it.
In this regard, the PR is not aimed at application developers, but instead aims to improve the user experience of those end-users.
As an example, instead of a traceback, the user now receives something like this:
Additionally, this PR closes #332 because I was getting annoyed at the failing tests
This feature is implemented by introducing our own custom exception type that is raised during Value setup and processing and caught by our importer. When caught, an error handler pretty-prints the information that is included in the exception. This information is, in turn, automatically retrieved from the relevant Value.
THIS IS STILL A WORK IN PROGRESS because I still want to include more actionable information in the error message. Nonetheless, the PR gives others the opportunity to chime in about the feature.
TODOs:
ConfigurationError
s to display well-formatted errors to end-users, howhelp_text
,help_reference
andexample_generator
can be used