Pretty and helpful exceptions, automatically
Project description
Note: This a fork of the original better_exceptions library. This fork is intended to fix some edge cases I reported (see #47), but for this it adds two dependencies to the project. The fixed errors are too small to justify the addition of dependency to the main library, hence this fork that I publish for personal use.
better-exceptions
Pretty and more helpful exceptions in Python, automatically.
Usage
Install better_exceptions via pip:
$ pip install better_exceptions
And set the BETTER_EXCEPTIONS environment variable to any value:
export BETTER_EXCEPTIONS=1 # Linux / OSX
setx BETTER_EXCEPTIONS 1 # Windows
That’s it!
Advanced Usage
If you want to allow the entirety of values to be outputted instead of being truncated to a certain amount of characters:
import better_exceptions
better_exceptions.MAX_LENGTH = None
While using better_exceptions in production, do not forget to unset the BETTER_EXCEPTIONS variable to avoid leaking sensitive data in your logs.
Troubleshooting
If you do not see beautiful exceptions, first make sure that the environment variable does exist. You can try echo $BETTER_EXCEPTIONS (Linux / OSX) or echo %BETTER_EXCEPTIONS% (Windows). On Linux and OSX, the export command does not add the variable permanently, you will probably need to edit the ~/.profile file to make it persistent. On Windows, you need to open a new terminal after the setx command.
You should also note that better_exceptions does not work inside the Python interactive shell, unless the executed code comes from another file.
Check that there is no conflict with another library, and that the sys.excepthook function has been correctly replaced with the better_exceptions’s one. Sometimes other components can set up their own exception handlers, such as the python3-apport Ubuntu package that you may need to uninstall.
Make sure that you have not inadvertently deleted the better_exceptions_hook.pth file that should be in the same place as the better_exceptions folder where all of your Python packages are installed. Otherwise, try re-installing better_exceptions.
You can also try to manually activate the hook by adding import better_exceptions; better_exceptions.hook() at the beginning of your script.
Finally, if you still can not get this module to work, open a new issue by describing your problem precisely and detailing your configuration (Python and better_exceptions versions, OS, code snippet, interpeter, etc.) so that we can reproduce the bug you are experiencing.
License
Copyright © 2017, Josh Junon. Licensed under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for better_exceptions_fork-0.1.8.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5044eef127a6a086069d01f823663f5ef2038dbfa92387dda452752351b2b5a9 |
|
MD5 | f118412aba5034c1c56f7f1ca3f2f079 |
|
BLAKE2b-256 | 53bf04e8226681dda6b9f8f11fe7ad421edef3b29bfe9de03ae1709e6f856a2c |