{"id":13448129,"url":"https://github.com/Qix-/better-exceptions","last_synced_at":"2025-03-22T02:30:43.611Z","repository":{"id":37390766,"uuid":"84720080","full_name":"Qix-/better-exceptions","owner":"Qix-","description":"Pretty and useful exceptions in Python, automatically.","archived":false,"fork":false,"pushed_at":"2023-03-23T11:09:43.000Z","size":234,"stargazers_count":4623,"open_issues_count":38,"forks_count":205,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-03-18T22:20:00.604Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qix-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"qix-"}},"created_at":"2017-03-12T11:23:04.000Z","updated_at":"2025-03-17T11:41:00.000Z","dependencies_parsed_at":"2024-04-02T11:04:54.717Z","dependency_job_id":null,"html_url":"https://github.com/Qix-/better-exceptions","commit_stats":{"total_commits":99,"total_committers":26,"mean_commits":"3.8076923076923075","dds":0.7171717171717171,"last_synced_commit":"f7f1476e57129dc74d241b4377b0df39c37bc8a7"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fbetter-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fbetter-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fbetter-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fbetter-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qix-","download_url":"https://codeload.github.com/Qix-/better-exceptions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244897651,"owners_count":20528274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:01:36.481Z","updated_at":"2025-03-22T02:30:43.307Z","avatar_url":"https://github.com/Qix-.png","language":"Python","readme":"# better-exceptions [![Travis](https://img.shields.io/travis/Qix-/better-exceptions.svg?style=flat-square)](https://travis-ci.org/Qix-/better-exceptions)\n\nPretty and more helpful exceptions in Python, automatically.\n\n![Example screenshot of exceptions](screenshot.png)\n\n## Usage\n\nInstall `better_exceptions` via pip:\n\n```console\npip install better_exceptions\n```\n\nAnd set the `BETTER_EXCEPTIONS` environment variable to any value:\n\n```bash\nexport BETTER_EXCEPTIONS=1  # Linux / OSX\nsetx BETTER_EXCEPTIONS 1    # Windows\n```\n\nThat's it!\n\n### Python REPL (Interactive Shell)\n\nIn order to use `better_exceptions` in the Python REPL, first install the package (as instructed above) and run:\n\n```console\n$ python -m better_exceptions\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n(BetterExceptionsConsole)\n\u003e\u003e\u003e\n```\n\nin order to drop into a `better_exceptions`-enabled Python interactive shell.\n\n### Advanced Usage\n\nIf you want to allow the entirety of values to be outputted instead of being truncated to a certain amount of characters:\n\n```python\nimport better_exceptions\nbetter_exceptions.MAX_LENGTH = None\n```\n\nWhile using `better_exceptions` in production, do not forget to unset the `BETTER_EXCEPTIONS` variable to avoid leaking sensitive data in your logs.\n\n### Use with unittest\n\nIf you want to use `better_exceptions` to format `unittest`'s exception output, you can use the monkey patch below:\n\n```python\nimport sys\nimport unittest\nimport better_exceptions\n\ndef patch(self, err, test):\n    lines = better_exceptions.format_exception(*err)\n    if sys.version_info[0] == 2:\n        return u\"\".join(lines).encode(\"utf-8\")\n    return \"\".join(lines)\n\nunittest.result.TestResult._exc_info_to_string = patch\n```\n\nNote that this uses an undocumented method override, so it is **not** guaranteed to work on all platforms or versions of Python.\n\n### Django Usage\n\nIn `settings.py`, add your new class to the `MIDDLEWARE` setting and update your logging configuration:\n\n```python\n# ...\n\nMIDDLEWARE = [\n    # ...\n    \"better_exceptions.integrations.django.BetterExceptionsMiddleware\",\n]\n\n# ...\n\nfrom better_exceptions.integrations.django import skip_errors_filter\n\n# if you don't want to override LOGGING because you want to change the default,\n# you can vendor Django's default logging configuration and update it for\n# better-exceptions. the default for Django 3.1.4 can be found here:\n# https://github.com/django/django/blob/3.1.4/django/utils/log.py#L13-L63\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'filters': {\n        'skip_errors': {\n            '()': 'django.utils.log.CallbackFilter',\n            'callback': skip_errors_filter,\n        }\n    },\n    'handlers': {\n        'console': {\n            'level': 'INFO',\n            # without the 'filters' key, Django will log errors twice:\n            # one time from better-exceptions and one time from Django.\n            # with the 'skip_errors' filter, we remove the repeat log\n            # from Django, which is unformatted.\n            'filters': ['skip_errors'],\n            'class': 'logging.StreamHandler',\n        }\n    },\n    'loggers': {\n        'django': {\n            'handlers': [\n                'console',\n            ],\n        }\n    }\n}\n```\n\nexample output:\n\n![image](https://user-images.githubusercontent.com/157132/56871937-5a07b480-69f1-11e9-9fd5-fac12382ebb7.png)\n\n## Troubleshooting\n\nIf 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.\n\nCheck 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.\n\nMake 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`.\n\nYou can also try to manually activate the hook by adding `import better_exceptions; better_exceptions.hook()` at the beginning of your script.\n\nFinally, if you still can not get this module to work, [open a new issue](https://github.com/Qix-/better-exceptions/issues/new) 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.\n\n# License\n\nCopyright \u0026copy; 2017, Josh Junon. Licensed under the [MIT license](LICENSE.txt).\n","funding_links":["https://github.com/sponsors/qix-"],"categories":["Python","Uncategorized","Logging"],"sub_categories":["Uncategorized","包"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQix-%2Fbetter-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FQix-%2Fbetter-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQix-%2Fbetter-exceptions/lists"}