From 557318af4e992089b11a4d65074bd1a9d7cc19f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 8 Feb 2018 17:10:58 +0100 Subject: [PATCH] Implement robust error handling in SourceCodeEventHandler --- src/event_handlers/source_code_event_handler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index b92cc80..3f128cf 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -57,21 +57,23 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): } def read(self, data): + try: data['content'] = self.filemanager.file_contents + except PermissionError: data['content'] = 'You have no permission to open that file :(' data['filename'] = self.filemanager.filename - data['content'] = self.filemanager.file_contents data['language'] = self.filemanager.language data['files'] = self.filemanager.files return data def write(self, data): - self.filemanager.file_contents = data['content'] + try: self.filemanager.file_contents = data['content'] + except Exception: log.exception('Error reading file!') data['files'] = self.filemanager.files self.restart_process() return data def select(self, data): try: self.filemanager.select_file(data['filename']) - except EnvironmentError: log.critical('Failed to select file "{}"'.format(data['filename'])) + except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename'])) return data def handle_event(self, anchor, data_json):