From f90d437a354cb03ec8fae3640c412401ebd63b45 Mon Sep 17 00:00:00 2001 From: Julien Date: Sun, 11 Oct 2026 15:20:27 +0200 Subject: [PATCH] Catch exceptions from subprocess run --- converter.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) 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: -- 2.47.3