Waitress needs clear error message on no WSGI app #60

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@mikeckennedy

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.

@mikeckennedy mikeckennedy 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.
f2c7001
@mcdonc mcdonc added a commit that referenced this pull request Jul 14, 2014
@mcdonc mcdonc - If an ``application`` value of ``None`` is supplied to the ``create…
…_server``

  constructor function, a ValueError is now raised eagerly instead of an error
  occuring during runtime.  See #60

Closes #60
77698fb
@mcdonc mcdonc added a commit that closed this pull request Jul 14, 2014
@mcdonc mcdonc - If an ``application`` value of ``None`` is supplied to the ``create…
…_server``

  constructor function, a ValueError is now raised eagerly instead of an error
  occuring during runtime.  See #60

Closes #60
77698fb
@mcdonc mcdonc closed this in 77698fb Jul 14, 2014
@mcdonc
Member
mcdonc commented Jul 14, 2014

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

@pcdude2143 pcdude2143 pushed a commit to pcdude2143/dotfiles that referenced this pull request Jul 20, 2014
Michael Shepard Squashed '.vim/bundle/YouCompleteMe.vim/third_party/waitress/' change…
…s from 3fab205..77698fb

77698fb - If an ``application`` value of ``None`` is supplied to the ``create_server``   constructor function, a ValueError is now raised eagerly instead of an error   occuring during runtime.  See Pylons/waitress#60
769c151 Add a ``docs`` section to tox.ini that, when run, ensures docs can be built.
0feff7a Add a ``docs`` section to tox.ini that, when run, ensures docs can be built.
d9eb9db change tests based on code changes and make more assertions
1e96d1d Merge branch 'master' of github.com:eli-collins/waitress into eli-collins-master
5b70bd3 - Use a nonglobal asyncore socket map by default to hopefully prevent conflicts   with apps and libs that use the asyncore global socket map ala   Pylons/waitress#63.  You can get the old   use-global-socket-map behavior back by passing ``asyncore.socket_map`` to the   ``create_server`` function as the ``map`` argument.
6c52026 Fix: start_response() should only re-raise exc_info if headers have been written

git-subtree-dir: .vim/bundle/YouCompleteMe.vim/third_party/waitress
git-subtree-split: 77698fbf35376bdd530493e5db262c256ebe87c4
d0a1868
@mikeckennedy

Thank you!

@pcdude2143 pcdude2143 pushed a commit to pcdude2143/dotfiles that referenced this pull request Dec 30, 2014
Michael Shepard Squashed '.vim/bundle/YouCompleteMe.vim/third_party/waitress/' change…
…s from 3fab205..eaaeeb5

eaaeeb5 Add Travis config.
3f7dc98 Add support for Python 3.4, PyPy3.
faa63fd Merge pull request #77 from msabramo/patch-1
a7389da index.rst: Add syntax highlighting
381f7ff Merge pull request #72 from tritium21/patch-1
2399d93 Update setup.py
77698fb - If an ``application`` value of ``None`` is supplied to the ``create_server``   constructor function, a ValueError is now raised eagerly instead of an error   occuring during runtime.  See Pylons/waitress#60
769c151 Add a ``docs`` section to tox.ini that, when run, ensures docs can be built.
0feff7a Add a ``docs`` section to tox.ini that, when run, ensures docs can be built.
d9eb9db change tests based on code changes and make more assertions
1e96d1d Merge branch 'master' of github.com:eli-collins/waitress into eli-collins-master
5b70bd3 - Use a nonglobal asyncore socket map by default to hopefully prevent conflicts   with apps and libs that use the asyncore global socket map ala   Pylons/waitress#63.  You can get the old   use-global-socket-map behavior back by passing ``asyncore.socket_map`` to the   ``create_server`` function as the ``map`` argument.
6c52026 Fix: start_response() should only re-raise exc_info if headers have been written

git-subtree-dir: .vim/bundle/YouCompleteMe.vim/third_party/waitress
git-subtree-split: eaaeeb503ce143a67a56011e018dd7c013ddeef0
0fb4699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment