changeset 246:5e65f52be453

make sure Bot.error doesn't raise a transcoding exception and uses repr() when there is a problem Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 18:39:53 +0100
parents cf4f00441628
children 303e571bc104
files bot.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bot.py
+++ b/bot.py
@@ -64,6 +64,10 @@ class Bot(threading.Thread):
 	
 	def error(self, importance, message, debug=False, no_debug_add='', send_to_admins=False):
 		"""Output an error message."""
+		try:
+			message = message.encode('utf-8')
+		except:
+			message = repr(message)
 		if not self.debug:
 			 message += no_debug_add
 		if send_to_admins == True:
@@ -71,9 +75,9 @@ class Bot(threading.Thread):
 		if importance == -1:
 			return
 		if not debug:
-			self.error_fd.write(self.format_message(importance, message).encode('utf-8')+'\n')
+			self.error_fd.write(self.format_message(importance, message)+'\n')
 		elif self.debug:
-			self.error_fd.write('='*importance+'> '+message.encode('utf-8')+'\n')
+			self.error_fd.write('='*importance+'> '+message+'\n')
 	
 	
 	def _xmpp_loop(self):