Implement robust error handling in SourceCodeEventHandler

This commit is contained in:
Kristóf Tóth 2018-02-08 17:10:58 +01:00
parent 8c492df646
commit 557318af4e

View File

@ -57,21 +57,23 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
} }
def read(self, data): 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['filename'] = self.filemanager.filename
data['content'] = self.filemanager.file_contents
data['language'] = self.filemanager.language data['language'] = self.filemanager.language
data['files'] = self.filemanager.files data['files'] = self.filemanager.files
return data return data
def write(self, 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 data['files'] = self.filemanager.files
self.restart_process() self.restart_process()
return data return data
def select(self, data): def select(self, data):
try: self.filemanager.select_file(data['filename']) 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 return data
def handle_event(self, anchor, data_json): def handle_event(self, anchor, data_json):