]> git.poda.fr Git - converter.git/commitdiff
Catch exceptions from subprocess run master
authorJulien <None>
Sun, 11 Oct 2026 13:20:27 +0000 (15:20 +0200)
committerJulien <None>
Sun, 11 Oct 2026 13:20:27 +0000 (15:20 +0200)
converter.py

index 9c513d62743e53a34744969267471000f581c93a..4c48edddd04bcaa9c8ff2c5f0608dec91e7c54dc 100755 (executable)
@@ -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: