From e5136bd340c93e18b86b286ec779d5e643d94aef Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Mon, 4 Jul 2011 13:20:19 -0700 Subject: [PATCH] Add a better error message for a common assertion --- tornado/web.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 -- 2.47.3