From 08dfc86ad2ae394b0eea79fc72819e02a79ad988 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 4 Mar 2019 11:09:20 +0100 Subject: [PATCH] Help: Don't fail on UnicodeEncodeError when saving search history to disk Also refactor a bit how history is saved. --- spyder/plugins/help.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spyder/plugins/help.py b/spyder/plugins/help.py index 902f3728378..50b7cbd651a 100644 --- a/spyder/plugins/help.py +++ b/spyder/plugins/help.py @@ -829,11 +829,14 @@ def load_history(self, obj=None): def save_history(self): """Save history to a text file in user home directory""" + # Don't fail when saving search history to disk + # See issues 8878 and 6864 try: - open(self.LOG_PATH, 'w').write("\n".join( \ - [to_text_string(self.combo.itemText(index)) - for index in range(self.combo.count())] )) - except (UnicodeDecodeError, EnvironmentError): + search_history = [to_text_string(self.combo.itemText(index)) + for index in range(self.combo.count())] + search_history = '\n'.join(search_history) + open(self.LOG_PATH, 'w').write(search_history) + except (UnicodeEncodeError, UnicodeDecodeError, EnvironmentError): pass @Slot(bool)