Auto cache and track Python exceptions via Python decorators.
Project description
Bug Buddy
Bug Buddy is a python library that helps you take action on exceptions in your code.
It is primarily a decorator that will locally cache exceptions and, if specified, upload the exception as a gitlab or github issue. Too often do we encounter bugs in our code that are not properly managed and fixed. Prescribing to the notion that code is in an ever-improving state, Bug Buddy helps devlopers track both high-frequency and one-off bugs by autocaching locally and uploading to a remote so they may be linked to appropriate update branches.
Installation
You can install Bug Buddy using pip:
pip install bug-buddy
Usage
First, set your remote's API token as an environment variable for your remote, these can be personal, project, or group access tokens.
Remote | Env Variable |
---|---|
Gitlab | $GITLAB_TOKEN |
Github | $GITHUB_TOKEN |
To use Bug Buddy, you need to import it and decorate the top-level callable of your code with @bug_buddy
. For example:
import pandas as pd
from bug_buddy import bug_buddy
@bug_buddy(project_id=43922234, gitlab=True)
def main() -> None:
"""Runner function.
Create a dataframe with two columns.
Expect to throw a ValueError with the exception logged
to Gitlab by bug_buddy.
"""
pd.DataFrame({"a": [1, 2, 3], "b": [4, 5]})
Running this code, Bug Buddy returns the exception traceback just as you'd normally expect.
As requested in @bug_buddy
, the issue is logged to Gitlab
In addition to the remote, the issue is cached to $HOME/.bug_buddy.cache
, to enable offline bug tracking.
[
{
"id": 140872896,
"title": "BugBuddy-4a8dd26c-2faa-4780-b01d-75965cf4896a",
"state": "opened",
"project_id": 43922234,
"author": "Spencer Seale_spencerseale_active",
"created_at": "2024-01-16T00:14:22.388Z",
"updated_at": "2024-01-16T00:14:22.388Z",
"description": "### Traceback\n| File | Callable | Line | Code |\n| --- | --- | --- | --- |\n| /Users/sseale/personal/bug-buddy/main.py | main | 18 | pd.DataFrame({\"a\": [1, 2, 3], \"b\": [4, 5]}) |\n| /Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/frame.py | \\_\\_init\\_\\_ | 733 | mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager) |\n| /Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py | dict\\_to\\_mgr | 503 | return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy) |\n| /Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py | arrays\\_to\\_mgr | 114 | index = _extract_index(arrays) |\n| /Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py | \\_extract\\_index | 677 | raise ValueError(\"All arrays must be of the same length\") |\n\n<details><summary>Raw traceback</summary>\nTraceback (most recent call last):\n File \"/Users/sseale/personal/bug-buddy/src/python/bug_buddy/listener.py\", line 149, in wrapper\n actual = runner(*args, **kwargs)\n File \"/Users/sseale/personal/bug-buddy/main.py\", line 18, in main\n pd.DataFrame({\"a\": [1, 2, 3], \"b\": [4, 5]})\n File \"/Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/frame.py\", line 733, in __init__\n mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)\n File \"/Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py\", line 503, in dict_to_mgr\n return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)\n File \"/Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py\", line 114, in arrays_to_mgr\n index = _extract_index(arrays)\n File \"/Users/sseale/miniconda3/envs/bug-buddy-py310/lib/python3.10/site-packages/pandas/core/internals/construction.py\", line 677, in _extract_index\n raise ValueError(\"All arrays must be of the same length\")\nValueError: All arrays must be of the same length\n\n</details>",
"labels": "BugBuddy_ValueError"
}
]
CLI
I'm still determining whether there is a need/desire to implement bug-buddy as a CLI tool. Its programatic integration serves its use case quite well at the moment. If you disagree please feel free to make a ticket, I'd love to hear your thoughts.
Parameters
The @bug_buddy
decorator accepts the following parameters:
project_id
: The ID of the repository that issues are to be created for. You can find the ID by going to the project's homepage and clicking on the Project information button.gitlab
: A boolean value indicating whether to upload the exception to Gitlab or not. Default isFalse
.github
: A boolean value indicating whether to upload the exception to Github or not. Default isFalse
.
Features
Bug Buddy has the following features:
- It supports both Gitlab and Github (IN DEV), and you can choose which one to use by setting the
gitlab
orgithub
parameter toTrue
. - It automatically creates a formatted issue for the exception, including the traceback, the code snippet, and the environment information.
- It tags the issue with exception type encountered.
- It caches the exceptions locally in a JSON file stored in
$HOME
, so you can access them offline or delete them if needed.
Contribute
Contributions are welcome! Please feel free to contribute at https://github.com/spencerseale/bugbuddy
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
Built Distribution
File details
Details for the file bug_buddy-1.0.4.tar.gz
.
File metadata
- Download URL: bug_buddy-1.0.4.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.12.0 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a123e34ce66a6ac16fd5053ca10a174fe5b104a0e8e5267bd71d0c11c33e20 |
|
MD5 | 97c0b6c77318ce179d75c3e4396add6f |
|
BLAKE2b-256 | 80c53c689c7dc3c86e15e54942e2024fd790aa126143f0640f91d509a4d7ca15 |
File details
Details for the file bug_buddy-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: bug_buddy-1.0.4-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.12.0 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1588b6d6f3b74e02908cd43f8af3059a3be8300c9748d4176c458a21fc489f8b |
|
MD5 | 7a63531118d5b60815cb0a9444df2d57 |
|
BLAKE2b-256 | ff2b6c4fea9117ebe6250039ad57d4cbef648a79e19d4e33a884280b4034673b |