Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed traceback formatting for syntax errors #1235

Merged
merged 1 commit into from Mar 24, 2016

Conversation

MarSoft
Copy link
Contributor

@MarSoft 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 Fixed traceback formatting Fixed traceback formatting for syntax errors Mar 24, 2016
@MarSoft
Copy link
Contributor Author

MarSoft commented Mar 24, 2016

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

@berkerpeksag
Copy link
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
Copy link
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
Copy link
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
Copy link
Collaborator

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

Thanks!

@tilgovi
Copy link
Collaborator

tilgovi commented Mar 24, 2016

Thanks, @MarSoft!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants