Qix-/better-exceptions là dự án mã nguồn mở trên GitHub, viết chủ yếu bằng Python, với 4.7k sao. Pretty and useful exceptions in Python, automatically.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
[!WARNING]
Thank you to everyone who has taken an interest in this project since I released it. It is now archived.
better-exceptions was a throwaway module I wrote one night while toying with Starbound mods. Figured I'd
release it because it was quasi-useful to me, and it blew up on Reddit overnight and somehow made its way
into being critical infra for some people.
With the onslaught of AI, I no longer have any interest or motivation to deal with this project. Further,
PyPi has made it clear they don't want to help me recover my accounts since my support requests have gone
unanswered for several months. I couldn't release a new version of this if I wanted to. I don't write Python
anymore, anyway.
better-exceptions was never meant to be used in production. If you're using it in production, stop.
It's never been vetted.
Further, a result of me archiving this means there will be forks and other versions of this that pop up
on PyPi or other places. Be very careful. This has been a very hot target of automated activity, and
I wouldn't be surprised if someone would try to include malware in some of those forks. I've been, quite
famously, a target for such attacks.
This was a fun project, until it wasn't. I appreciate everyone's feedback, input and contributions over the
years.
- Josh
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!
Python REPL (Interactive Shell)
In order to use better_exceptions in the Python REPL, first install the package (as instructed above) and run:
$ python -m better_exceptions
Type "help", "copyright", "credits" or "license" for more information.
(BetterExceptionsConsole)
>>>
in order to drop into a better_exceptions-enabled Python interactive shell.
Advanced Usage
If you want to allow the entirety of values to be outputted instead of being truncated to a certain amount of characters:
Note that this uses an undocumented method override, so it is not guaranteed to work on all platforms or versions of Python.
Django Usage
In settings.py, add your new class to the MIDDLEWARE setting and update your logging configuration:
# ...
MIDDLEWARE = [
# ...
"better_exceptions.integrations.django.BetterExceptionsMiddleware",
]
# ...
from better_exceptions.integrations.django import skip_errors_filter
# if you don't want to override LOGGING because you want to change the default,
# you can vendor Django's default logging configuration and update it for
# better-exceptions. the default for Django 3.1.4 can be found here:
# https://github.com/django/django/blob/3.1.4/django/utils/log.py#L13-L63
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'skip_errors': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_errors_filter,
}
},
'handlers': {
'console': {
'level': 'INFO',
# without the 'filters' key, Django will log errors twice:
# one time from better-exceptions and one time from Django.
# with the 'skip_errors' filter, we remove the repeat log
# from Django, which is unformatted.
'filters': ['skip_errors'],
'class': 'logging.StreamHandler',
}
},
'loggers': {
'django': {
'handlers': [
'console',
],
}
}
}
example output:
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.
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, interpreter, etc.) so that we can reproduce the bug you are experiencing.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/Qix-/better-exceptions là nguồn chính thức.
Qix-/better-exceptions có phải mã nguồn mở không?
Có — Qix-/better-exceptions phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/Qix-/better-exceptions.
Qix-/better-exceptions có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho Qix-/better-exceptions. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
Qix-/better-exceptions có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho Qix-/better-exceptions. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
Qix-/better-exceptions còn đang phát triển không?
Commit gần nhất trên Qix-/better-exceptions là 1 tháng trước (theo timestamp GitHub). Repo có 231 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Qix-/better-exceptions dùng license gì?
Qix-/better-exceptions phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc better-exceptions có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về better-exceptions.