From 3b241a3930b206718628e8f3fdf863693a14e219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 9 Mar 2018 09:07:21 +0100 Subject: [PATCH] Implement error handling in SourceCodeEventHandler.select_dir() --- lib/tfw/components/source_code_event_handler.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index b4f474f..993d744 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -90,8 +90,15 @@ class SourceCodeEventHandler(TriggerlessEventHandler): return data def select_dir(self, data): - try: self.filemanager.workdir = data['directory'] - except EnvironmentError: log.exception('Failed to select directory "{}"'.format(data['directory'])) + try: + self.filemanager.workdir = data['directory'] + try: + self.filemanager.select_file(self.filemanager.files[0]) + data['content'] = self.filemanager.file_contents + except IndexError: + data['content'] = 'No files in this directory :(' + except EnvironmentError: + log.exception('Failed to select directory "{}"'.format(data['directory'])) return data def attach_fileinfo(self, data):