我友好的错误基类-用于python。
mybad的Python项目详细描述
mybad
我的友好错误基类-用于python。
简介
一般情况下,一个错误总是需要一个特定于应用程序/库的错误基类,但是本机错误在出现时所能保存的元/调试信息非常有限。为了更好地调试和错误报告/检查,这个错误基类允许附加一些额外的错误上下文信息,这些信息可以用来更好地理解问题,而无需创建自定义错误格式化程序或运行调试器。
安装
使用pip安装
非常基本的example: 使用可选的环境变量 类似这样(想象一些彩色格式): 克隆源代码:$ pip install mybad
使用
frommybadimportErrorclassToMuchError(Error):passdefprint_money(stash):try:ifisinstance(stash,str)andlen(stash)>13:raiseException('Too much money to print: {0}'.format(stash))print('PRINT {0}'.format(stash))exceptExceptionaserror:raiseToMuchError(error,message='Out of money printing ink...',id=hash(stash),key='too_much',code=400,details=dict(stash=stash,))amount=''fordollarinrange(42):amount+='$'print_money(amount)
COLORS
/ERROR_COLORS
和/或VERBOSE
/ERROR_VERBOSE
运行此命令,设置太大或错误的值,请参阅终端中的各种错误信息格式。PRINT $
PRINT $$
PRINT $$$
PRINT $$$$
PRINT $$$$$
PRINT $$$$$$
PRINT $$$$$$$
PRINT $$$$$$$$
PRINT $$$$$$$$$
PRINT $$$$$$$$$$
PRINT $$$$$$$$$$$
PRINT $$$$$$$$$$$$
PRINT $$$$$$$$$$$$$
===============================
str(error)
---------------------------
Out of money printing ink... - {'stash': '$$$$$$$$$$$$$$'}===============================
error.stack
---------------------------
Traceback (most recent call last):
File "examples/basic.py", line 27, in print_money
raise Exception('Too much money to print: {0}'.format(stash))
Exception: Too much money to print: $$$$$$$$$$$$$$===============================
error.inspect()
---------------------------
{'code': 400,
'details': {'stash': '$$$$$$$$$$$$$$'},
'id': 3563898309523127190,
'key': 'too_much',
'message': 'Out of money printing ink...',
'stack': [{'code': ['stash = stash,'],
'file': 'examples/basic.py',
'function': 'print_money',
'line': 38},
{'code': ['print_money(amount)'],
'file': 'examples/basic.py',
'function': '<module>',
'line': 48}],
'type': 'ToMuchError'}===============================
error.json()
---------------------------
{"type": "ToMuchError",
"id": 3563898309523127190,
"code": 400,
"key": "too_much",
"message": "Out of money printing ink...",
"details": {"stash": "$$$$$$$$$$$$$$"},
"stack": [{"file": "examples/basic.py",
"function": "print_money",
"line": 38,
"code": ["stash = stash,"]},
{"file": "examples/basic.py",
"function": "<module>",
"line": 48,
"code": ["print_money(amount)"]}]}
测试
$ make install
<>运行^ ^ {STR 1 } $多彩测试>,只使用本地环境(依赖沙箱向上):
$ make test
使用multi environment(使用tox)运行less colorgy测试:
$ make test-tox
相关
- ^{
} -“我的友好库基类-用于python”
关于
这个项目主要是在缺乏现有的替代方案的情况下使用的,在我们的工作中使用^ {STR 1 } $Markable.ai在各种编程环境之间有共同的代码约定,其中{STR 1 } $ Python (研究,CV,AI)被大量使用。
许可证
在麻省理工学院的许可下发布。