From: Ben Darnell Date: Mon, 4 Jul 2011 20:20:19 +0000 (-0700) Subject: Add a better error message for a common assertion X-Git-Tag: v2.1.0~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5136bd340c93e18b86b286ec779d5e643d94aef;p=thirdparty%2Ftornado.git Add a better error message for a common assertion --- diff --git a/tornado/web.py b/tornado/web.py index fbffbdfa3..497d7e9f5 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -444,7 +444,10 @@ class RequestHandler(object): wrapped in a dictionary. More details at http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx """ - assert not self._finished + if self._finished: + raise RuntimeError("Cannot write() after finish(). May be caused " + "by using async operations without the " + "@asynchronous decorator.") if isinstance(chunk, dict): chunk = escape.json_encode(chunk) self.set_header("Content-Type", "application/json; charset=UTF-8") @@ -606,7 +609,11 @@ class RequestHandler(object): def finish(self, chunk=None): """Finishes this response, ending the HTTP request.""" - assert not self._finished + if self._finished: + raise RuntimeError("finish() called twice. May be caused " + "by using async operations without the " + "@asynchronous decorator.") + if chunk is not None: self.write(chunk) # Automatically support ETags and add the Content-Length header if