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

Waitress needs clear error message on no WSGI app #60

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@mikeckennedy

mikeckennedy commented May 5, 2014

If a WSGI application was not passed to waitress, no errors are raised during server start up and only a confusing error message in the output (and nothing useful in the HTTP response). This request improves the error message in the log.

While this may seem unnecessary, it is a very easy beginner mistake to use this init.py code in your Pyramid app:

#BAD!
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""
    config = Configurator(settings=settings)
    dependencies.configure(config)
    routing.configure(config)
    config.make_wsgi_app() # YIKES forgot return keyword 

The result of running the site with the missing return value is an error basically like this:

pserve /site/development.ini
Starting server in PID 7817.
serving on http://0.0.0.0:6543
2014-05-04 16:45:51,285 ERROR [waitress][Dummy-1] Exception when serving /
Traceback (most recent call last):
  File "/Users/mkennedy/programming/github/waitress/waitress/channel.py", line 337, in service
    task.service()
  File "/Users/mkennedy/programming/github/waitress/waitress/task.py", line 173, in service
    self.execute()
  File "/Users/mkennedy/programming/github/waitress/waitress/task.py", line 396, in execute
    app_iter = self.channel.server.application(env, start_response)
TypeError: 'NoneType' object is not callable

That is entirely non-debuggable and non-googlable. With my proposed change, you'll see:

...
  File "/Users/mkennedy/programming/github/waitress/waitress/task.py", line 393, in execute
    raise Exception("Cannot process request (WSGI application missing). "
Exception: Cannot process request (WSGI application missing). Was None pass where WSGI application was expected?

I think this is much more helpful.

I originally tried to verify this on server start rather than first request. But so many of the unit tests pass None for app that I decided it wasn't worth the trouble.

Waitress needs clear error message on no WSGI app
If a WSGI application was not passed to waitress, no errors are raised
and only confusing error messages are the result. This improves the
error message.

@mcdonc mcdonc closed this in 77698fb Jul 14, 2014

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Jul 14, 2014

Member

Thanks. I did not use your pull request, but I've added the feature a different way.

Member

mcdonc commented Jul 14, 2014

Thanks. I did not use your pull request, but I've added the feature a different way.

@mikeckennedy

This comment has been minimized.

Show comment
Hide comment
@mikeckennedy

mikeckennedy commented Jul 21, 2014

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment