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) msg = message.format(*args)
elif len(kwargs) > 0: elif len(kwargs) > 0:
msg = message.format(**kwargs) msg = message.format(**kwargs)
try:
print('[WakaTime] [{lvl}] {msg}'.format(lvl=lvl, msg=msg)) print('[WakaTime] [{lvl}] {msg}'.format(lvl=lvl, msg=msg))
except UnicodeDecodeError:
print(u('[WakaTime] [{lvl}] {msg}').format(lvl=lvl, msg=u(msg)))
except RuntimeError: except RuntimeError:
set_timeout(lambda: log(lvl, message, *args, **kwargs), 0) set_timeout(lambda: log(lvl, message, *args, **kwargs), 0)