Eugeny / Eugeny/catcher

Strange behaviour with Flask

Open
#2 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
131
Forks
12
PR merge metrics
No merged PRs in 30d

Description

Simple example (yes, Flask is imported but not used):

``` python
import sys

from flask import Flask
import catcher

def exception_handler(exc_type, exc, tb):
exc.traceback_backup = tb
report = catcher.collect(exc)
print catcher.formatters.HTMLFormatter().format(report)

def fail():
1 / 0

sys.excepthook = exception_handler
fail()

```

I get the error:

```
Error in sys.excepthook:
Traceback (most recent call last):
File "example.py", line 11, in exception_handler
print catcher.formatters.HTMLFormatter().format(report)
File "/home/eslezko/.virtualenvs/marylin/local/lib/python2.7/site-packages/catcher/formatters/html.py", line 161, in format
return _template.render(maxdepth=maxdepth, report=report, datetime=datetime)
File "/home/eslezko/.virtualenvs/marylin/local/lib/python2.7/site-packages/mako/template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "/home/eslezko/.virtualenvs/marylin/local/lib/python2.7/site-packages/mako/runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "/home/eslezko/.virtualenvs/marylin/local/lib/python2.7/site-packages/mako/runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/eslezko/.virtualenvs/marylin/local/lib/python2.7/site-packages/mako/runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "memory:0x1ea6450", line 95, in render_body
File "memory:0x1ea6450", line 19, in object
File "memory:0x1ea6450", line 160, in render_object
File "memory:0x1ea6450", line 112, in object
File "memory:0x1ea6450", line 196, in render_object
File "memory:0x1ea6450", line 112, in object
File "memory:0x1ea6450", line 160, in render_object
File "memory:0x1ea6450", line 112, in object
File "memory:0x1ea6450", line 150, in render_object
RuntimeError: dictionary changed size during iteration

Original exception was:
Traceback (most recent call last):
File "example.py", line 19, in
fail()
File "example.py", line 15, in fail
1 / 0
ZeroDivisionError: integer division or modulo by zero
```

Without flask import catcher works well.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the example with the Flask import and follow the traceback to catcher/formatters/html.py, especially HTMLFormatter.format. Compare the behavior with and without Flask, then run the existing project tests if available. Done means the example no longer raises the formatter error while reporting the original exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.