From c5742349275b10f3e451340d448cc9576cc6a302 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Wed, 8 Feb 2017 19:24:26 -0800 Subject: [PATCH] prevent crashing when logging object unable to be converted to unicode --- WakaTime.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WakaTime.py b/WakaTime.py index 07b05e3..b076ee9 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -47,6 +47,8 @@ if is_py2: def u(text): if text is None: return None + if isinstance(text, unicode): + return text try: return text.decode('utf-8') except: @@ -58,8 +60,11 @@ if is_py2: except: try: return text.decode('utf-8', 'replace') - except AttributeError: - return unicode(str(text)) + except: + try: + return unicode(str(text)) + except: + return unicode('') elif is_py3: def u(text):