💥 Use OSError as the general system-related exception

According to PEP 3151, OSError can be used for all system-related exceptions and thus replace IOError, EnvironmentError, socket.error, etc.
This commit is contained in:
Miroslav Šedivý committed 2021-01-25 18:04:47 +01:00
1 parent 95441dafd4
commit 35e35d92a6
9 files changed
+21 -21

No files matched your search

+2 -2
View File
@@ -87,7 +87,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
stderr=(subprocess.PIPE if hide_stderr else None),
)
break
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
@@ -151,7 +151,7 @@ def git_get_keywords(versionfile_abs):
if mo:
keywords["full"] = mo.group(1)
f.close()
except EnvironmentError:
except OSError:
pass
return keywords
+1 -1
View File
@@ -155,7 +155,7 @@ class Daemon:
try:
with io.open(self.pidfile, "rt", encoding="utf-8") as pf:
pid = int(pf.read().strip())
except (IOError, ValueError):
except (OSError, ValueError):
pid = None
return pid
+1 -1
View File
@@ -2306,7 +2306,7 @@ class EntryPointMetadata(pkginfo.Distribution):
for metadata_file in metadata_files:
try:
return self.entry_point.dist.get_metadata(metadata_file)
except (IOError, OSError): # noqa: B014
except OSError: # noqa: B014
# file not found, metadata file might be missing, ignore
# IOError: file not found in Py2
# OSError (specifically FileNotFoundError): file not found in Py3
@@ -153,7 +153,7 @@ def _git(args, cwd, git_executable=None):
command = [c] + args
try:
return _execute(command, cwd=cwd)
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
@@ -30,7 +30,7 @@ def _git(args, cwd, hide_stderr=False):
stderr=(subprocess.PIPE if hide_stderr else None),
)
break
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
+3 -3
View File
@@ -208,7 +208,7 @@ def fix_webassets_cache():
try:
hash = make_md5(self.V, key)
except IOError as e:
except OSError as e:
if e.errno != errno.ENOENT:
raise
return None
@@ -216,7 +216,7 @@ def fix_webassets_cache():
filename = os.path.join(self.directory, "%s" % hash)
try:
f = io.open(filename, "rb")
except IOError as e:
except OSError as e:
if e.errno != errno.ENOENT:
error_logger.exception(
"Got an exception while trying to open webasset file {}".format(
@@ -1020,7 +1020,7 @@ class PreemptiveCache:
try:
with io.open(self.cachefile, "rt") as f:
cache_data = yaml.safe_load(f)
except IOError as e:
except OSError as e:
import errno
if e.errno != errno.ENOENT:
+6 -6
View File
@@ -2178,7 +2178,7 @@ def _validate_folder(
if not os.path.exists(folder):
if os.path.islink(folder):
# broken symlink, see #2644
raise IOError("Folder at {} appears to be a broken symlink".format(folder))
raise OSError("Folder at {} appears to be a broken symlink".format(folder))
elif create:
# non existing, but we are allowed to create it
@@ -2187,7 +2187,7 @@ def _validate_folder(
except Exception:
if log_error:
logger.exception("Could not create {}".format(folder))
raise IOError(
raise OSError(
"Folder for type {} at {} does not exist and creation failed".format(
type, folder
)
@@ -2195,11 +2195,11 @@ def _validate_folder(
else:
# not extisting, not allowed to create it
raise IOError("No such folder: {}".format(folder))
raise OSError("No such folder: {}".format(folder))
elif os.path.isfile(folder):
# hardening against misconfiguration, see #1953
raise IOError("Expected a folder at {} but found a file instead".format(folder))
raise OSError("Expected a folder at {} but found a file instead".format(folder))
elif check_writable:
# make sure we can also write into the folder
@@ -2207,7 +2207,7 @@ def _validate_folder(
folder
)
if not os.access(folder, os.W_OK):
raise IOError(error)
raise OSError(error)
elif deep_check_writable:
# try to write a file to the folder - on network shares that might be the only reliable way
@@ -2220,4 +2220,4 @@ def _validate_folder(
except Exception:
if log_error:
logger.exception("Could not write test file to {}".format(folder))
raise IOError(error)
raise OSError(error)
+4 -4
View File
@@ -424,7 +424,7 @@ class SlicingManager:
try:
path = self.get_profile_path(slicer, name, must_exist=True)
except IOError:
except OSError:
return None
return self._load_profile_from_path(
slicer, path, require_configured=require_configured
@@ -532,7 +532,7 @@ class SlicingManager:
if name:
try:
profile = self.load_profile(slicer, name)
except (UnknownProfile, IOError):
except (UnknownProfile, OSError):
# in that case we'll use the default profile
pass
@@ -728,7 +728,7 @@ class SlicingManager:
self.get_slicer_profile_path(slicer), "{name}.profile".format(name=name)
)
if not os.path.realpath(path).startswith(os.path.realpath(self._profile_path)):
raise IOError(
raise OSError(
"Path to profile {name} tried to break out of allows sub path".format(
**locals()
)
@@ -782,7 +782,7 @@ class SlicingManager:
if default_profiles and slicer in default_profiles:
try:
return self.load_profile(slicer, default_profiles[slicer])
except (UnknownProfile, IOError):
except (UnknownProfile, OSError):
# in that case we'll use the slicers predefined default profile
pass
+2 -2
View File
@@ -3874,7 +3874,7 @@ class MachineCom:
try:
line, pos, lineno = self._currentFile.getNext()
except EnvironmentError:
except OSError:
self._log(
"There was an error reading from the file that's being printed, cancelling the print. Please "
"consult octoprint.log for details on the error."
@@ -5462,7 +5462,7 @@ class PrintingGcodeFileInformation(PrintingFileInformation):
self._current_tool_callback = current_tool_callback
if not os.path.exists(self._filename) or not os.path.isfile(self._filename):
raise IOError("File %s does not exist" % self._filename)
raise OSError("File %s does not exist" % self._filename)
self._size = os.stat(self._filename).st_size
self._pos = 0
self._read_lines = 0