Skip to content

Commit 69f0a5a

Browse files
committed
feature/enhancement: new more developer friendly API, and consistent with js-mybad
1 parent 2f405cd commit 69f0a5a

File tree

7 files changed

+621
-114
lines changed

7 files changed

+621
-114
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ install:
4444
.PHONY: install-ci
4545
install-ci:
4646
PYTHON_USER_FLAG=$(shell python -c "import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') else '--user')") && \
47-
pip install $(PYTHON_USER_FLAG) -U setuptools setuptools-git tox tox-travis && \
47+
pip install $(PYTHON_USER_FLAG) -U setuptools setuptools-git setupextras tox tox-travis && \
4848
pip install $(PYTHON_USER_FLAG) -r requirements.txt
4949

5050

README.md

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,70 @@ PRINT $$$$$$$$$$
7272
PRINT $$$$$$$$$$$
7373
PRINT $$$$$$$$$$$$
7474
PRINT $$$$$$$$$$$$$
75-
Out of money printing ink... - { stash: '$$$$$$$$$$$$$$' }
76-
75+
===============================
76+
str(error)
77+
---------------------------
78+
Out of money printing ink... - {'stash': '$$$$$$$$$$$$$$'}
79+
80+
===============================
81+
error.stack
82+
---------------------------
7783
Traceback (most recent call last):
78-
File "examples/basic.py", line 25, in print_money
84+
File "examples/basic.py", line 27, in print_money
7985
raise Exception('Too much money to print: {0}'.format(stash))
8086
Exception: Too much money to print: $$$$$$$$$$$$$$
8187

82-
During handling of the above exception, another exception occurred:
88+
===============================
89+
error.inspect()
90+
---------------------------
91+
{ 'code': 400,
92+
'details': {'stash': '$$$$$$$$$$$$$$'},
93+
'id': 3563898309523127190,
94+
'key': 'too_much',
95+
'message': 'Out of money printing ink...',
96+
'stack': [ { 'code': ['stash = stash,'],
97+
'file': 'examples/basic.py',
98+
'function': 'print_money',
99+
'line': 38},
100+
{ 'code': ['print_money(amount)'],
101+
'file': 'examples/basic.py',
102+
'function': '<module>',
103+
'line': 48}],
104+
'type': 'ToMuchError'}
105+
106+
107+
===============================
108+
error.json()
109+
---------------------------
110+
{
111+
"type": "ToMuchError",
112+
"id": 3563898309523127190,
113+
"code": 400,
114+
"key": "too_much",
115+
"message": "Out of money printing ink...",
116+
"details": {
117+
"stash": "$$$$$$$$$$$$$$"
118+
},
119+
"stack": [
120+
{
121+
"file": "examples/basic.py",
122+
"function": "print_money",
123+
"line": 38,
124+
"code": [
125+
"stash = stash,"
126+
]
127+
},
128+
{
129+
"file": "examples/basic.py",
130+
"function": "<module>",
131+
"line": 48,
132+
"code": [
133+
"print_money(amount)"
134+
]
135+
}
136+
]
137+
}
83138

84-
Traceback (most recent call last):
85-
File "examples/basic.py", line 45, in <module>
86-
print_money(amount)
87-
File "examples/basic.py", line 36, in print_money
88-
stash = stash,
89-
__main__.ToMuchError: Out of money printing ink... - {'stash': '$$$$$$$$$$$$$$'}
90139
```
91140
92141

examples/basic.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
rootpath.append()
99

10+
import json
11+
1012

1113
# =========================================
1214
# EXAMPLE
@@ -46,7 +48,27 @@ def print_money(stash):
4648
print_money(amount)
4749

4850
except Exception as error:
51+
print('===============================')
52+
print(' str(error)')
53+
print('---------------------------')
4954
print(str(error))
50-
51-
raise error
52-
55+
print()
56+
57+
print('===============================')
58+
print(' error.stack')
59+
print('---------------------------')
60+
print(error.stack)
61+
62+
print('===============================')
63+
print(' error.inspect()')
64+
print('---------------------------')
65+
print(error.inspect(colors = True, verbose = True))
66+
print()
67+
68+
print('===============================')
69+
print(' error.json()')
70+
print('---------------------------')
71+
print(error.json())
72+
print()
73+
74+
break

0 commit comments

Comments
 (0)