diff --git a/src/octoprint/_version.py b/src/octoprint/_version.py index 48d4df8f8..7920e56d2 100644 --- a/src/octoprint/_version.py +++ b/src/octoprint/_version.py @@ -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 diff --git a/src/octoprint/daemon.py b/src/octoprint/daemon.py index 4efc884d3..7548e23c2 100644 --- a/src/octoprint/daemon.py +++ b/src/octoprint/daemon.py @@ -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 diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 6bbe076de..4c3618722 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -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 diff --git a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py index b0297df8e..9f03044cd 100644 --- a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py +++ b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py @@ -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 diff --git a/src/octoprint/plugins/softwareupdate/version_checks/git_commit.py b/src/octoprint/plugins/softwareupdate/version_checks/git_commit.py index 589feb997..72f431b7f 100644 --- a/src/octoprint/plugins/softwareupdate/version_checks/git_commit.py +++ b/src/octoprint/plugins/softwareupdate/version_checks/git_commit.py @@ -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 diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 613d8988f..06c53bd04 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -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: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index bfcd95c08..bcbfdb542 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -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) diff --git a/src/octoprint/slicing/__init__.py b/src/octoprint/slicing/__init__.py index b18c69a3f..c22f74b7a 100644 --- a/src/octoprint/slicing/__init__.py +++ b/src/octoprint/slicing/__init__.py @@ -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 diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index e3cd55437..b8bc1113f 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -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