From 7634be54469e471ddbe6d62bc43dfb9d09a7967f Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 23 Sep 2016 08:36:23 +0200 Subject: [PATCH] handle UnicodeDecodeError exceptions when printing log messages --- WakaTime.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WakaTime.py b/WakaTime.py index 6e70cfa..d61effc 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -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)