From: Julien Date: Sun, 11 Oct 2026 13:20:27 +0000 (+0200) Subject: Catch exceptions from subprocess run X-Git-Url: https://git.poda.fr/?a=commitdiff_plain;h=HEAD;p=converter.git Catch exceptions from subprocess run --- diff --git a/converter.py b/converter.py index 9c513d6..4c48edd 100755 --- a/converter.py +++ b/converter.py @@ -254,10 +254,20 @@ class Converter: self._log("Error: Invalid convert profile \"" + convertParams.convertProfile + "\".") return - if not self.checkConverter(convertParams.converterPath, self._CONVERTER_CHECK): + command: list[str] = [convertParams.converterPath] + [self._CONVERTER_CHECK] + result: subprocess.CompletedProcess + + try: + result = subprocess.run(command, capture_output=True, text=True) + except: self._log("Error: Could not start converter \"" + convertParams.converterPath + "\".") return + if result.returncode != 0: + self._log("Error: Could not start converter \"" + convertParams.converterPath + + "\": " + result.stderr) + return + if convertParams.jobs < 1: self._log("Error: Number of concurrent jobs must be at least 1.") return @@ -498,8 +508,15 @@ class Converter: command: list[str] = ([converterPath] + [self._CONVERTER_IN] + [task.inputFilePath] + task.converterArgs + [outputFilePathWip]) - result: subprocess.CompletedProcess = subprocess.run( - command, capture_output=True, text=True) + result: subprocess.CompletedProcess + + try: + result = subprocess.run(command, capture_output=True, text=True) + except: + self._log("Error converting file \"" + task.inputFilePath + + "\" into \"" + task.outputFilePath + "\".") + stats.errors += 1 + return if result.returncode != 0: self._log("Error from converter on file \"" @@ -718,14 +735,6 @@ class Converter: def isFileIdentical(self, firstFilePath: str, secondFilePath: str) -> bool: return filecmp.cmp(firstFilePath, secondFilePath, shallow=False) - - def checkConverter(self, converterPath: str, converterArg: str) -> bool: - try: - return subprocess.run([converterPath, converterArg], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL).returncode == 0 - except: - return False; # /Converter class GUI: