From 22bb95b9ee15156ce06b58d5d416d6077bb7ad78 Mon Sep 17 00:00:00 2001 From: ianb Date: Wed, 21 Dec 2005 18:43:35 +0000 Subject: Improve error messages in assertions --- paste/httpexceptions.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'paste/httpexceptions.py') diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py index cd08909..5ee0cb0 100644 --- a/paste/httpexceptions.py +++ b/paste/httpexceptions.py @@ -152,12 +152,19 @@ class HTTPException(Exception): def __init__(self, detail=None, headers=None, comment=None): assert self.code, "Do not directly instantiate abstract exceptions." - assert isinstance(headers, (type(None), list)) - assert isinstance(detail, (type(None), basestring)) - assert isinstance(comment, (type(None), basestring)) + assert isinstance(headers, (type(None), list)), ( + "headers must be None or a list: %r" + % headers) + assert isinstance(detail, (type(None), basestring)), ( + "detail must be None or a string: %r" % detail) + assert isinstance(comment, (type(None), basestring)), ( + "comment must be None or a string: %r" % comment) self.headers = headers or tuple() for req in self.required_headers: - assert headers and has_header(headers, req) + assert headers and has_header(headers, req), ( + "Exception %s must be passed the header %r " + "(got headers: %r)" + % (self.__class__.__name__, req, headers)) if detail is not None: self.detail = detail if comment is not None: -- cgit v1.2.1