Fixed broad exceptions

Fixed broad exception errors: replacing them with more precise error
catching where sensible and adding appropriate pylint skip comments
where not.
This commit is contained in:
Marta Marczykowska-Górecka 2017-11-08 15:40:35 +01:00
parent 2b24abb8c8
commit d7fbacf0d7
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 43 additions and 27 deletions

View File

@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui
import qubesadmin import qubesadmin
import qubesadmin.tools import qubesadmin.tools
import qubesadmin.exc
from . import utils from . import utils
@ -174,8 +175,10 @@ class NewVmDlg(QtGui.QDialog, Ui_NewVMDlg):
for k, v in properties.items(): for k, v in properties.items():
setattr(vm, k, v) setattr(vm, k, v)
except Exception as ex: except qubesadmin.exc.QubesException as qex:
thread_monitor.set_error_msg(str(ex)) thread_monitor.set_error_msg(str(qex))
except Exception as ex: # pylint: disable=broad-except
thread_monitor.set_error_msg(repr(ex))
thread_monitor.set_finished() thread_monitor.set_finished()

View File

@ -31,6 +31,7 @@ import traceback
import os import os
import sys import sys
from qubesadmin.tools import QubesArgumentParser from qubesadmin.tools import QubesArgumentParser
import qubesadmin.exc
from . import utils from . import utils
from . import multiselectwidget from . import multiselectwidget
@ -188,8 +189,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
ret_tmp = self.__apply_services_tab__() ret_tmp = self.__apply_services_tab__()
if len(ret_tmp) > 0: if len(ret_tmp) > 0:
ret += ["Sevices tab:"] + ret_tmp ret += ["Sevices tab:"] + ret_tmp
except Exception as ex: except qubesadmin.exc.QubesException as qex:
ret.append(self.tr('Error while saving changes: ') + str(ex)) ret.append(self.tr('Error while saving changes: ') + str(qex))
except Exception as ex: # pylint: disable=broad-except
ret.append(repr(ex))
try: try:
if self.policyAllowRadioButton.isEnabled(): if self.policyAllowRadioButton.isEnabled():
@ -200,14 +203,18 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.fw_model.fw_changed: if self.fw_model.fw_changed:
# might modified vm.services # might modified vm.services
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as qex:
ret += [self.tr("Firewall tab:"), str(ex)] ret+= [self.tr("Firewall tab:"), str(qex)]
except Exception as ex: # pylint: disable=broad-except
ret += [self.tr("Firewall tab:"), repr(ex)]
try: try:
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]): if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
self.AppListManager.save_appmenu_select_changes() self.AppListManager.save_appmenu_select_changes()
except Exception as ex: except qubesadmin.exc.QubesException as qex:
ret += [self.tr("Applications tab:"), str(ex)] ret += [self.tr("Applications tab:"), str(qex)]
except Exception as ex: # pylint: disable=broad-except
ret += [self.tr("Applications tab:"), repr(ex)]
if len(ret) > 0: if len(ret) > 0:
t_monitor.set_error_msg('\n'.join(ret)) t_monitor.set_error_msg('\n'.join(ret))
@ -342,7 +349,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
label = self.label_list[self.vmlabel.currentIndex()] label = self.label_list[self.vmlabel.currentIndex()]
self.vm.label = label self.vm.label = label
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#vm template changed #vm template changed
@ -351,7 +358,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.vm.template = \ self.vm.template = \
self.template_list[self.template_name.currentIndex()] self.template_list[self.template_name.currentIndex()]
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#vm netvm changed #vm netvm changed
@ -359,7 +366,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.netVM.currentIndex() != self.netvm_idx: if self.netVM.currentIndex() != self.netvm_idx:
self.vm.netvm = self.netvm_list[self.netVM.currentIndex()] self.vm.netvm = self.netvm_list[self.netVM.currentIndex()]
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#include in backups #include in backups
@ -368,7 +375,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.include_in_backups.isChecked(): self.include_in_backups.isChecked():
self.vm.include_in_backups = self.include_in_backups.isChecked() self.vm.include_in_backups = self.include_in_backups.isChecked()
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#run_in_debug_mode #run_in_debug_mode
@ -377,7 +384,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.vm.debug != self.run_in_debug_mode.isChecked(): if self.vm.debug != self.run_in_debug_mode.isChecked():
self.vm.debug = self.run_in_debug_mode.isChecked() self.vm.debug = self.run_in_debug_mode.isChecked()
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#autostart_vm #autostart_vm
@ -386,7 +393,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.vm.autostart != self.autostart_vm.isChecked(): if self.vm.autostart != self.autostart_vm.isChecked():
self.vm.autostart = self.autostart_vm.isChecked() self.vm.autostart = self.autostart_vm.isChecked()
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#max priv storage #max priv storage
@ -395,7 +402,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
self.vm.volumes['private'].resize(priv_size * 1024**2) self.vm.volumes['private'].resize(priv_size * 1024**2)
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#max sys storage #max sys storage
@ -404,7 +411,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
self.vm.volumes['root'].resize(sys_size * 1024**2) self.vm.volumes['root'].resize(sys_size * 1024**2)
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
return msg return msg
@ -452,8 +459,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.vm.app.clone_vm(self.vm, name) self.vm.app.clone_vm(self.vm, name)
del self.vm.app.domains[self.vm.name] del self.vm.app.domains[self.vm.name]
except Exception as ex: except qubesadmin.exc.QubesException as qex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(qex))
except Exception as ex: # pylint: disable=broad-except
t_monitor.set_error_msg(repr(ex))
t_monitor.set_finished() t_monitor.set_finished()
@ -473,8 +482,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
del self.vm.app.domains[self.vm.name] del self.vm.app.domains[self.vm.name]
except Exception as ex: except qubesadmin.exc.QubesException as qex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(qex))
except Exception as ex: # pylint: disable=broad-except
t_monitor.set_error_msg(repr(ex))
t_monitor.set_finished() t_monitor.set_finished()
@ -503,8 +514,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
self.vm.app.clone_vm(self.vm, name) self.vm.app.clone_vm(self.vm, name)
except Exception as ex: except qubesadmin.exc.QubesException as qex:
t_monitor.set_error_msg(str(ex)) t_monitor.set_error_msg(str(qex))
except Exception as ex: # pylint: disable=broad-except
t_monitor.set_error_msg(repr(ex))
t_monitor.set_finished() t_monitor.set_finished()
@ -584,7 +597,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.vcpus.value() != int(self.vm.vcpus): if self.vcpus.value() != int(self.vm.vcpus):
self.vm.vcpus = self.vcpus.value() self.vm.vcpus = self.vcpus.value()
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#include_in_memory_balancing applied in services tab #include_in_memory_balancing applied in services tab
@ -596,7 +609,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.vm.kernel = self.kernel_list[ self.vm.kernel = self.kernel_list[
self.kernel.currentIndex()] self.kernel.currentIndex()]
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
#vm default_dispvm changed #vm default_dispvm changed
@ -605,7 +618,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.vm.default_dispvm = \ self.vm.default_dispvm = \
self.default_dispvm_list[self.default_dispvm.currentIndex()] self.default_dispvm_list[self.default_dispvm.currentIndex()]
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
return msg return msg
@ -680,7 +693,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.anything_changed = True self.anything_changed = True
except Exception as ex: except qubesadmin.exc.QubesException as ex:
if utils.is_debug(): if utils.is_debug():
traceback.print_exc() traceback.print_exc()
msg.append(str(ex)) msg.append(str(ex))
@ -847,7 +860,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
service = feature[len('service.'):] service = feature[len('service.'):]
if service not in self.new_srv_dict: if service not in self.new_srv_dict:
del self.vm.features[feature] del self.vm.features[feature]
except Exception as ex: except qubesadmin.exc.QubesException as ex:
msg.append(str(ex)) msg.append(str(ex))
return msg return msg