Skip to content

Commit

Permalink
Fix duplicate-handler-exception in OSError exceptions
Browse files Browse the repository at this point in the history
IOError is covered by OSError since Python 3.3 so
lines like:

except (OSError, IOError) as e:

Were being marked with warning B014.

Signed-off-by: Jose Castillo <[email protected]>
  • Loading branch information
jcastill authored and arif-ali committed Nov 26, 2024
1 parent 0c70fa9 commit 9ee0572
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sos/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _update_from_section(section, config):
try:
with open(config_file, encoding='utf-8') as f:
config.read_file(f, config_file)
except (OSError, IOError) as e:
except OSError as e:
print(
f'WARNING: Unable to read configuration file {config_file} : '
f'{e.args[1]}'
Expand Down
20 changes: 10 additions & 10 deletions sos/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ def prework(self):
self.setup_archive()
self._make_archive_paths()
return
except (OSError, IOError) as e:
except OSError as e:
# we must not use the logging subsystem here as it is potentially
# in an inconsistent or unreliable state (e.g. an EROFS for the
# file system containing our temporary log files).
Expand Down Expand Up @@ -1258,7 +1258,7 @@ def setup(self):
plug.manifest.add_field('setup_time', end - start)
except KeyboardInterrupt:
raise KeyboardInterrupt # pylint: disable=raise-missing-from
except (OSError, IOError) as e:
except OSError as e:
if e.errno in fatal_fs_errors:
self.ui_log.error("")
self.ui_log.error(
Expand Down Expand Up @@ -1395,7 +1395,7 @@ def collect_plugin(self, plugin):
# we already log and handle the plugin timeout in the nested thread
# pool this is running in, so don't do anything here.
pass
except (OSError, IOError) as e:
except OSError as e:
if e.errno in fatal_fs_errors:
self.ui_log.error(
f"\n {e.strerror} while collecting plugin data")
Expand Down Expand Up @@ -1473,7 +1473,7 @@ def generate_reports(self):
fd.flush()
self.archive.add_file(fd, dest=os.path.join('sos_reports',
filename))
except (OSError, IOError) as e:
except OSError as e:
if e.errno in fatal_fs_errors:
self.ui_log.error("")
self.ui_log.error(
Expand All @@ -1494,7 +1494,7 @@ def postproc(self):
else:
self.soslog.info(
f"Skipping postproc for plugin {plugname}")
except (OSError, IOError) as e:
except OSError as e:
if e.errno in fatal_fs_errors:
self.ui_log.error("")
self.ui_log.error(
Expand Down Expand Up @@ -1616,7 +1616,7 @@ def final_work(self):
self.archive.rename_archive_root(cleaner)
archive = self.archive.finalize(
self.opts.compression_type)
except (OSError, IOError) as e:
except OSError as e:
print("")
print(_(f" {e.strerror} while finalizing archive "
f"{self.archive.get_archive_path()}"))
Expand All @@ -1643,7 +1643,7 @@ def final_work(self):
final_dir = os.path.join(self.sys_tmp, dir_name)
os.rename(directory, final_dir)
directory = final_dir
except (OSError, IOError):
except OSError:
print(_(f"Error moving directory: {directory}"))
return False

Expand All @@ -1665,7 +1665,7 @@ def final_work(self):
return False
try:
self._write_checksum(archive, hash_name, checksum)
except (OSError, IOError):
except OSError:
print(_(f"Error writing checksum for file: {archive}"))

# output filename is in the private tmpdir - move it to the
Expand All @@ -1686,7 +1686,7 @@ def final_work(self):
try:
os.rename(archive, final_name)
archive = final_name
except (OSError, IOError):
except OSError:
print(_(f"Error moving archive file: {archive}"))
return False

Expand All @@ -1704,7 +1704,7 @@ def final_work(self):
# under the control of the user creating the link.
try:
os.rename(archive_hash, final_hash)
except (OSError, IOError):
except OSError:
print(_(f"Error moving checksum file: {archive_hash}"))

self.policy.display_results(archive, directory, checksum,
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ def do_file_sub(self, srcpath, regexp, subst):
if not path:
return 0
replacements = self.archive.do_file_sub(path, regexp, subst)
except (OSError, IOError) as e:
except OSError as e:
# if trying to regexp a nonexisting file, dont log it as an
# error to stdout
if e.errno == errno.ENOENT:
Expand Down Expand Up @@ -1499,7 +1499,7 @@ def _do_copy_path(self, srcpath, dest=None, force=False):

try:
st = os.lstat(srcpath)
except (OSError, IOError):
except OSError:
self._log_info(f"failed to stat '{srcpath}'")
return None

Expand Down

0 comments on commit 9ee0572

Please sign in to comment.