Skip to content

Commit

Permalink
DBManager: replace the deprecated Exception.message attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed May 27, 2013
1 parent f5aef0f commit 5d8964a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions python/plugins/db_manager/db_plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@
class BaseError(Exception):
"""Base class for exceptions in the plugin."""
def __init__(self, e):
msg = e if isinstance(e, (str,unicode,QString)) else e.message
if isinstance(e, Exception):
msg = e.args[0] if len(e.args) > 0 else ''
else:
msg = e

try:
msg = unicode( msg )
except UnicodeDecodeError:
msg = unicode( msg, 'utf-8' )

self.msg = msg
Exception.__init__(self, msg)

def __unicode__(self):
return self.message
return self.msg

def __str__(self):
return unicode(self).encode('utf-8')
Expand All @@ -55,7 +60,7 @@ def __init__(self, e, query=None):
self.query = unicode( query ) if query != None else None

def __unicode__(self):
if self.query == None:
if self.query is None:
return BaseError.__unicode__(self)

msg = u"Error:\n%s" % BaseError.__unicode__(self)
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/db_manager/dlg_db_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(self, e, parent=None):
def sanitize(txt):
return "" if txt == None else "<pre>" + txt.replace('<','&lt;') + "</pre>"

if isinstance(e, DbError) and hasattr(e, 'query'):
self.setQueryMessage( sanitize(e.message), sanitize(e.query) )
if isinstance(e, DbError):
self.setQueryMessage( sanitize(e.msg), sanitize(e.query) )
else:
self.setMessage( sanitize(e.message) )
self.setMessage( sanitize(e.msg) )

def setMessage(self, msg):
self.txtErrorMsg.setHtml(msg)
Expand Down

0 comments on commit 5d8964a

Please sign in to comment.