Skip to content

Commit a684fcb

Browse files
committed
pylint: narrow down too general exception catches
Signed-off-by: Ales Novak <alnovak@suse.com>
1 parent 96fe63a commit a684fcb

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

nvmet/nvme.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def set_attr(self, group, attribute, value):
178178
try:
179179
with open(path, 'w', encoding="utf-8") as file_fd:
180180
file_fd.write(str(value))
181-
except Exception as e:
181+
except OSError as e:
182182
raise CFSError(f"Cannot set attribute {path}: {e}") from e
183183

184184
def get_attr(self, group, attribute):
@@ -222,7 +222,7 @@ def set_enable(self, value):
222222
try:
223223
with open(path, 'w', encoding="utf-8") as file_fd:
224224
file_fd.write(str(value))
225-
except Exception as e:
225+
except OSError as e:
226226
raise CFSError(f"Cannot enable {self.path}: {e} ({value})") from e
227227
self._enable = value
228228

@@ -304,7 +304,7 @@ def _modprobe(self, modname):
304304
try:
305305
kmod_ctypes.Kmod().modprobe(modname)
306306
return
307-
except Exception:
307+
except OSError:
308308
pass
309309

310310
# Try the binary specified in /proc
@@ -315,7 +315,7 @@ def _modprobe(self, modname):
315315
if modprobe_cmd:
316316
subprocess.run(shlex.split(modprobe_cmd) + [modname],
317317
check=False)
318-
except Exception:
318+
except OSError:
319319
pass
320320

321321
def _list_subsystems(self):
@@ -554,7 +554,7 @@ def add_allowed_host(self, nqn):
554554
try:
555555
os.symlink(f"{self.configfs_dir}/hosts/{nqn}",
556556
f"{self._path}/allowed_hosts/{nqn}")
557-
except Exception as e:
557+
except OSError as e:
558558
raise CFSError(f"Could not symlink {nqn} in configFS: {e}") from e
559559

560560
def remove_allowed_host(self, nqn):
@@ -563,7 +563,7 @@ def remove_allowed_host(self, nqn):
563563
'''
564564
try:
565565
os.unlink(f"{self._path}/allowed_hosts/{nqn}")
566-
except Exception as e:
566+
except OSError as e:
567567
raise CFSError(f"Could not unlink {nqn} in configFS: {e}") from e
568568

569569
def has_passthru(self):
@@ -895,7 +895,7 @@ def add_subsystem(self, nqn):
895895
try:
896896
os.symlink(f"{self.configfs_dir}/subsystems/{nqn}",
897897
f"{self._path}/subsystems/{nqn}")
898-
except Exception as e:
898+
except OSError as e:
899899
raise CFSError(f"Could not symlink {nqn} in configFS: {e}") from e
900900

901901
def remove_subsystem(self, nqn):
@@ -904,7 +904,7 @@ def remove_subsystem(self, nqn):
904904
'''
905905
try:
906906
os.unlink(f"{self._path}/subsystems/{nqn}")
907-
except Exception as e:
907+
except OSError as e:
908908
raise CFSError(f"Could not unlink {nqn} in configFS: {e}") from e
909909

910910
def delete(self):

nvmetcli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,14 @@ def main():
981981
try:
982982
shell = configshell.ConfigShell('~/.nvmetcli')
983983
UIRootNode(shell)
984-
except Exception as msg:
984+
except (nvme.CFSError, configshell.ExecutionError) as msg:
985985
shell.log.error(str(msg))
986986
return
987987

988988
while not shell._exit: # pylint: disable=protected-access
989989
try:
990990
shell.run_interactive()
991-
except Exception as msg:
991+
except (nvme.CFSError, configshell.ExecutionError) as msg:
992992
shell.log.error(str(msg))
993993

994994

0 commit comments

Comments
 (0)