alexmojaki / alexmojaki/stack_data

Differences in handling exceptions?

Aberta
#24 2 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
51
Forks
23
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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
```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.