Permalink
Browse files

__str__ for UserException so you know what the error was when using t…

…he repl
  • Loading branch information...
1 parent db5202c commit b04f83f1428b34702cc0a408ab744b265b11562a @freeformz freeformz committed with Daniel Farina Dec 6, 2011
Showing with 23 additions and 0 deletions.
  1. +5 −0 tests.py
  2. +18 −0 wal_e/exception.py
View
@@ -0,0 +1,5 @@
+import doctest
+
+import wal_e.exception
+
+doctest.testmod(wal_e.exception)
View
@@ -1,4 +1,6 @@
from logging import ERROR, CRITICAL
+from logging import getLevelName
+from wal_e.log_help import WalELogger
class UserException(Exception):
@@ -13,6 +15,18 @@ class UserException(Exception):
If it is necessary to trap these exceptions. use a subclass.
+ >>> raise UserException(msg='foo', detail='bar')
+ Traceback (most recent call last):
+ ...
+ UserException: ERROR: MSG: foo
+ DETAIL: bar
+
+ >>> raise UserException(msg='foo', detail='bar', hint='hello')
+ Traceback (most recent call last):
+ ...
+ UserException: ERROR: MSG: foo
+ DETAIL: bar
+ HINT: hello
"""
def __init__(self, msg=None, detail=None, hint=None):
@@ -25,6 +39,10 @@ def __init__(self, msg=None, detail=None, hint=None):
self.hint = hint
self.severity = ERROR
+ def __str__(self):
+ return "{0}: {1}".format(getLevelName(self.severity),
+ WalELogger.fmt_logline(self.msg, self.detail, self.hint))
+
class UserCritical(UserException):
"""

0 comments on commit b04f83f

Please sign in to comment.