Skip to content

Commit f97d742

Browse files
authored
Improve exception handling - replace generic Exception with specific types (#3032)
1 parent 2b5b8c8 commit f97d742

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/robotide/controller/dataloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _run(self):
100100
if not self.language:
101101
try:
102102
self.language = lang.check_file_language(self._path)
103-
except Exception:
103+
except (OSError, IOError, UnicodeDecodeError):
104104
self.language = 'en'
105105
return test_data(source=self._path, settings=self._settings, language=self.language)
106106

@@ -120,7 +120,7 @@ def _run(self):
120120
if not self.language:
121121
try:
122122
self.language = lang.check_file_language(self._path)
123-
except Exception:
123+
except (OSError, IOError, UnicodeDecodeError):
124124
self.language = 'en'
125125
robotapi.FromFilePopulator(result, lang=self.language).populate(self._path)
126126
return result

src/robotide/spec/libraryfinder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ def find_install_command(self, name):
171171
return []
172172
try:
173173
plug = self.global_settings['Plugins'][self.name][name]
174-
except Exception:
174+
except (KeyError, TypeError):
175175
plug = None
176176
if plug:
177177
try:
178178
return plug['command']
179-
except Exception:
179+
except (KeyError, TypeError):
180180
pass
181181
return []
182182

183183
def parse_command(self, command: list) -> list:
184184
try:
185185
executable = self.global_settings['executable']
186-
except Exception:
186+
except (KeyError, TypeError):
187187
executable = sys.executable
188188
parsed = []
189189
for cmd in command:
@@ -205,12 +205,12 @@ def run_install(self, library_name, command):
205205
def find_documentation_url(self, name):
206206
try:
207207
plug = self.global_settings['Plugins'][self.name][name]
208-
except Exception:
208+
except (KeyError, TypeError):
209209
plug = None
210210
if plug:
211211
try:
212212
return plug['documentation']
213-
except Exception:
213+
except (KeyError, TypeError):
214214
pass
215215
if self._is_std_library(name):
216216
if name == "Remote":

src/robotide/ui/fileexplorerplugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def update_tree(self):
335335
try:
336336
self.tree_ctrl.ExpandPath(self._controller.data.source)
337337
self.tree_ctrl.TreeCtrl.EnsureVisible(self.tree_ctrl.TreeCtrl.GetSelection())
338-
except Exception:
338+
except (RuntimeError, AttributeError):
339339
pass
340340
# self.on_size(wx.EVT_SIZE)
341341
self.Refresh()

src/robotide/ui/notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def on_tab_changing(self, event):
8585
oldselect = event.GetOldSelection()
8686
try:
8787
oldtitle = self.GetPageText(oldselect)
88-
except Exception:
88+
except (wx.wxAssertionError, RuntimeError):
8989
oldtitle = ""
9090
newindex = event.GetSelection()
9191
newtitle = self.GetPageText(event.GetSelection())

src/robotide/utils/eventhandler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _exclude_paths(self):
114114
item = os.path.join(item, '')
115115
try:
116116
self._fs_watcher.RemoveTree(item)
117-
except Exception:
117+
except (OSError, RuntimeError):
118118
pass
119119
# Remove all files to the monitoring list
120120
from wx import FileSystem
@@ -134,7 +134,7 @@ def _exclude_paths(self):
134134
pass
135135
try:
136136
self._fs_watcher.Remove(changing_file)
137-
except Exception:
137+
except (OSError, RuntimeError):
138138
pass
139139
try:
140140
file_search = fs.FindNext()
@@ -152,7 +152,7 @@ def _exclude_paths(self):
152152
pass
153153
try:
154154
self._fs_watcher.Remove(item)
155-
except Exception:
155+
except (OSError, RuntimeError):
156156
pass
157157

158158
def exclude_listening(self, path):

0 commit comments

Comments
 (0)