alexmojaki / alexmojaki/stack_data

Differences in handling exceptions?

Đang mở
#24 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
51
Fork
23
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I observe differences when handling different kind of exceptions
In an interactive interpreter:

```python
>>> import stack_data.formatting
>>> stack_data.formatting.Formatter(show_variables=True).set_hook()
```

A simple exception:

```python
>>> a=1
>>> a/0
Traceback (most recent call last):
File "", line 1, in
ZeroDivisionError: division by zero
```

(By the way the variable "a" is not shown)

Another kind of exception:

```python
>>> 1+
Traceback (most recent call last):
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 67, in Formatter.set_hook..excepthook
66 | def excepthook(_etype, evalue, _tb):
--> 67 | self.print_exception(evalue)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_etype =
_tb = None
evalue = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
self =
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 72, in Formatter.print_exception
71 | def print_exception(self, e=None, *, file=None):
--> 72 | self.print_lines(self.format_exception(e), file=file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
file = None
self =
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 83, in Formatter.print_lines
80 | def print_lines(self, lines, *, file=None):
81 | if file is None:
82 | file = sys.stderr
--> 83 | for line in lines:
84 | print(line, file=file, end="")
file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
file is None = False
line = ' 84 | print(line, file=file, end="")\n'
lines =
self =
sys.stderr = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 100, in Formatter.format_exception
96 | yield from self.format_exception(e.__context__)
97 | yield traceback._context_message
99 | yield 'Traceback (most recent call last):\n'
--> 100 | yield from self.format_stack(e.__traceback__)
101 | yield from traceback.format_exception_only(type(e), e)
e = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
e is None = False
e.__suppress_context__ = False
not e.__suppress_context__ = True
self =
self.chain = True
traceback._cause_message = '\nThe above exception was the direct cause of the following exception:\n\n'
traceback._context_message = '\nDuring handling of the above exception, another exception occurred:\n\n'
type(e) =
File "", line 1
1+
^
SyntaxError: invalid syntax
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.