{"id":19951364,"url":"https://github.com/grimen/python-mybad","last_synced_at":"2025-05-03T18:34:04.323Z","repository":{"id":34052437,"uuid":"167766172","full_name":"grimen/python-mybad","owner":"grimen","description":"My friendly error base class - for Python.","archived":false,"fork":false,"pushed_at":"2022-04-26T10:15:11.000Z","size":48,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-01T20:28:53.466Z","etag":null,"topics":["baseclass","color","colors","debug","detailed","error","errors","inspector","meta","pretty","python","python2","python3","stacktrace"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/mybad","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/grimen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-27T03:41:02.000Z","updated_at":"2023-01-03T17:12:00.000Z","dependencies_parsed_at":"2022-08-08T00:00:17.635Z","dependency_job_id":null,"html_url":"https://github.com/grimen/python-mybad","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-mybad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-mybad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-mybad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-mybad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grimen","download_url":"https://codeload.github.com/grimen/python-mybad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224370068,"owners_count":17299969,"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":["baseclass","color","colors","debug","detailed","error","errors","inspector","meta","pretty","python","python2","python3","stacktrace"],"created_at":"2024-11-13T01:07:47.942Z","updated_at":"2024-11-13T01:07:48.382Z","avatar_url":"https://github.com/grimen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# `mybad` [![PyPI version](https://badge.fury.io/py/mybad.svg)](https://badge.fury.io/py/mybad) [![Build Status](https://travis-ci.com/grimen/python-mybad.svg?branch=master)](https://travis-ci.com/grimen/python-mybad) [![Coverage Status](https://codecov.io/gh/grimen/python-mybad/branch/master/graph/badge.svg)](https://codecov.io/gh/grimen/python-mybad)\n\n*My friendly error base class - for Python.*\n\n\n## Introduction\n\nOne in general always needs a application/library specific error base class, but the native errors are very limited in what meta/debugging information they can hold at time they are raised. For better debugging and error reporting/inspection this error base class allows to attach some additonal error context information that can be used to better understand the issue - without having to create custom error formatters, or run debugger.\n\n\n## Install\n\nInstall using **pip**:\n\n```sh\n$ pip install mybad\n```\n\n\n## Use\n\nVery basic **[example](https://github.com/grimen/python-mybad/tree/master/examples/basic.py)**:\n\n```python\nfrom mybad import Error\n\nclass ToMuchError(Error):\n    pass\n\ndef print_money(stash):\n    try:\n        if isinstance(stash, str) and len(stash) \u003e 13:\n            raise Exception('Too much money to print: {0}'.format(stash))\n\n        print('PRINT {0}'.format(stash))\n\n    except Exception as error:\n        raise ToMuchError(error,\n            message = 'Out of money printing ink...',\n            id = hash(stash),\n            key = 'too_much',\n            code = 400,\n            details = dict(\n                stash = stash,\n            )\n        )\n\namount = ''\n\nfor dollar in range(42):\n    amount += '$'\n\n    print_money(amount)\n\n```\n\nRun this with optional environment variables `COLORS` / `ERROR_COLORS` and/or `VERBOSE` / `ERROR_VERBOSE` set too truthy or falsy values, so see various error info formatting in terminal.\n\nSomething like this (imagine some colorized formatting):\n\n```bash\nPRINT $\nPRINT $$\nPRINT $$$\nPRINT $$$$\nPRINT $$$$$\nPRINT $$$$$$\nPRINT $$$$$$$\nPRINT $$$$$$$$\nPRINT $$$$$$$$$\nPRINT $$$$$$$$$$\nPRINT $$$$$$$$$$$\nPRINT $$$$$$$$$$$$\nPRINT $$$$$$$$$$$$$\n===============================\n     str(error)\n---------------------------\nOut of money printing ink... - {'stash': '$$$$$$$$$$$$$$'}\n\n===============================\n     error.stack\n---------------------------\nTraceback (most recent call last):\n  File \"examples/basic.py\", line 27, in print_money\n    raise Exception('Too much money to print: {0}'.format(stash))\nException: Too much money to print: $$$$$$$$$$$$$$\n\n===============================\n     error.inspect()\n---------------------------\n{   'code': 400,\n    'details': {'stash': '$$$$$$$$$$$$$$'},\n    'id': 3563898309523127190,\n    'key': 'too_much',\n    'message': 'Out of money printing ink...',\n    'stack': [   {   'code': ['stash = stash,'],\n                     'file': 'examples/basic.py',\n                     'function': 'print_money',\n                     'line': 38},\n                 {   'code': ['print_money(amount)'],\n                     'file': 'examples/basic.py',\n                     'function': '\u003cmodule\u003e',\n                     'line': 48}],\n    'type': 'ToMuchError'}\n\n\n===============================\n     error.json()\n---------------------------\n{\n    \"type\": \"ToMuchError\",\n    \"id\": 3563898309523127190,\n    \"code\": 400,\n    \"key\": \"too_much\",\n    \"message\": \"Out of money printing ink...\",\n    \"details\": {\n        \"stash\": \"$$$$$$$$$$$$$$\"\n    },\n    \"stack\": [\n        {\n            \"file\": \"examples/basic.py\",\n            \"function\": \"print_money\",\n            \"line\": 38,\n            \"code\": [\n                \"stash = stash,\"\n            ]\n        },\n        {\n            \"file\": \"examples/basic.py\",\n            \"function\": \"\u003cmodule\u003e\",\n            \"line\": 48,\n            \"code\": [\n                \"print_money(amount)\"\n            ]\n        }\n    ]\n}\n\n```\n\n\n## Test\n\nClone down source code:\n\n```sh\n$ make install\n```\n\nRun **colorful tests**, with only native environment (dependency sandboxing up to you):\n\n```sh\n$ make test\n```\n\nRun **less colorful tests**, with **multi-environment** (using **tox**):\n\n```sh\n$ make test-tox\n```\n\n\n## Related\n\n- [**`node-mybad`**](https://github.com/grimen/python-mybase) - *\"My friendly error base class - for Node/JavaScript\"*\n- [**`python-mybase`**](https://github.com/grimen/python-mybase) - *\"My friendly library base class - for Python\"*\n\n\n## About\n\nThis project was mainly initiated - in lack of solid existing alternatives - to be used at our work at **[Markable.ai](https://markable.ai)** to have common code conventions between various programming environments where **Python** (research, CV, AI) is heavily used.\n\n\n## License\n\nReleased under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-mybad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrimen%2Fpython-mybad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-mybad/lists"}