handle UnicodeDecodeError exceptions when printing log messages

This commit is contained in:
Alan Hamlett 2016-09-23 08:36:23 +02:00
parent 5e17ad88f6
commit 7634be5446

View File

@ -135,7 +135,10 @@ def log(lvl, message, *args, **kwargs):
msg = message.format(*args)
elif len(kwargs) > 0:
msg = message.format(**kwargs)
print('[WakaTime] [{lvl}] {msg}'.format(lvl=lvl, msg=msg))
try:
print('[WakaTime] [{lvl}] {msg}'.format(lvl=lvl, msg=msg))
except UnicodeDecodeError:
print(u('[WakaTime] [{lvl}] {msg}').format(lvl=lvl, msg=u(msg)))
except RuntimeError:
set_timeout(lambda: log(lvl, message, *args, **kwargs), 0)