Fixed traceback formatting for syntax errors #1235

Merged
merged 1 commit into from Mar 24, 2016

Projects

None yet

3 participants

@MarSoft
Contributor
MarSoft commented Mar 24, 2016

Without this patch, on current Gunicorn version I get the following traceback if I have a syntax error in my program:

  ...
  File "/home/mars/myproject/views/item.py", line 494
    return render(request, 'add_item.html',
         ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python3.5/site-packages/aiohttp-0.21.2-py3.5-linux-x86_64.egg/aiohttp/worker.py", line 30, in init_process
    super().init_process()
  File "/usr/lib/python3.5/site-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python3.5/site-packages/gunicorn/workers/base.py", line 140, in load_wsgi
    tb_string = traceback.format_exc(exc_tb)
  File "/usr/lib/python3.5/traceback.py", line 163, in format_exc
    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "/usr/lib/python3.5/traceback.py", line 117, in format_exception
    type(value), value, tb, limit=limit).format(chain=chain))
  File "/usr/lib/python3.5/traceback.py", line 474, in __init__
    capture_locals=capture_locals)
  File "/usr/lib/python3.5/traceback.py", line 332, in extract
    if limit >= 0:
TypeError: unorderable types: traceback() >= int()

This patch removes additional "During handling of the above exception..." traceback.

@MarSoft MarSoft changed the title from Fixed traceback formatting to Fixed traceback formatting for syntax errors Mar 24, 2016
@MarSoft
Contributor
MarSoft commented Mar 24, 2016

I have no idea how to properly test this or where to place such tests..

@berkerpeksag
Collaborator

Did you get the same traceback in Python 3.4? This might be a regression in Python 3.5's traceback module. I have already fixed two of them in Python 3.5.

@tilgovi
Collaborator
tilgovi commented Mar 24, 2016

Actually, I think this is just an error that needs to be corrected, @berkerpeksag. The format_exc function takes a limit argument, not a traceback. I missed this when reviewing #1228.

@tilgovi
Collaborator
tilgovi commented Mar 24, 2016

Or rather, the bug was there before #1228 reformatted it :).

@tilgovi tilgovi added the Bug label Mar 24, 2016
@berkerpeksag
Collaborator

You're right, I keep forgetting traceback API :) Looks good to me.

Thanks!

@tilgovi
Collaborator
tilgovi commented Mar 24, 2016

Thanks, @MarSoft!

@tilgovi tilgovi merged commit 3b0529d into benoitc:master Mar 24, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment