Jelajahi Sumber

Replace bare except clauses with except Exception throughout

Bare `except:` also catches BaseException subclasses like KeyboardInterrupt
and SystemExit, which can silently swallow signals or interfere with normal
interpreter shutdown. Replaced all occurrences across cli.py, mux.py,
probe.py, proc.py, scan.py, and tag.py.

Also replaces the two `except BaseException as e:` in mux.py for the same
reason.
ZiB 4 bulan lalu
induk
melakukan
bab235346f

+ 2 - 2
zz_remux/zz_remux/cli.py

@@ -28,7 +28,7 @@ def main():
   args = None
   args = None
   try:
   try:
     args = parser.parse_args()
     args = parser.parse_args()
-  except:
+  except Exception:
     parser.print_help()
     parser.print_help()
     sys.exit(-1)
     sys.exit(-1)
   if args.debug:
   if args.debug:
@@ -47,7 +47,7 @@ def main():
     try:
     try:
       match = re.compile(args.match, re.IGNORECASE)
       match = re.compile(args.match, re.IGNORECASE)
       args.match = True
       args.match = True
-    except:
+    except Exception:
       print(f"Unable to compile match regex: {args.match}", file=sys.stderr)
       print(f"Unable to compile match regex: {args.match}", file=sys.stderr)
       parser.print_help()
       parser.print_help()
       sys.exit(-1)
       sys.exit(-1)

+ 2 - 2
zz_remux/zz_remux/mux.py

@@ -104,7 +104,7 @@ class Mux:
           self.logger.info(f"Removing: {source['path'].name}")
           self.logger.info(f"Removing: {source['path'].name}")
           source['path'].unlink()
           source['path'].unlink()
           media.remove(source)
           media.remove(source)
-      except BaseException as e:
+      except Exception as e:
         self.logger.error(f"Unlink error: {e}")
         self.logger.error(f"Unlink error: {e}")
         continue
         continue
 
 
@@ -120,7 +120,7 @@ class Mux:
         info['group']    = videos[0]['group']
         info['group']    = videos[0]['group']
         info['mux_vers'] = Consts.mux_vers
         info['mux_vers'] = Consts.mux_vers
         media.append(info)
         media.append(info)
-      except BaseException as e:
+      except Exception as e:
         err = e
         err = e
       if not final.exists():
       if not final.exists():
         err = 'file missing'
         err = 'file missing'

+ 1 - 1
zz_remux/zz_remux/probe.py

@@ -33,7 +33,7 @@ class Probe:
     streams = None
     streams = None
     try:
     try:
       streams = json.loads(probe['out'])['streams']
       streams = json.loads(probe['out'])['streams']
-    except:
+    except Exception:
       pass
       pass
     if not streams or len(streams) < 1:
     if not streams or len(streams) < 1:
       err = f"Unable to parse: {path}"
       err = f"Unable to parse: {path}"

+ 3 - 3
zz_remux/zz_remux/proc.py

@@ -27,19 +27,19 @@ class Proc:
     # Exit code
     # Exit code
     try:
     try:
       ret['code'] = proc.returncode
       ret['code'] = proc.returncode
-    except:
+    except Exception:
       pass
       pass
 
 
     # Decode outputs
     # Decode outputs
     if hasattr(proc, 'stdout') and len(proc.stdout) > 0:
     if hasattr(proc, 'stdout') and len(proc.stdout) > 0:
       try:
       try:
         ret['out'] = proc.stdout.decode(self.encoding)
         ret['out'] = proc.stdout.decode(self.encoding)
-      except:
+      except Exception:
         pass
         pass
     if hasattr(proc, 'stderr') and len(proc.stderr) > 0:
     if hasattr(proc, 'stderr') and len(proc.stderr) > 0:
       try:
       try:
         ret['err'] = proc.stderr.decode(self.encoding)
         ret['err'] = proc.stderr.decode(self.encoding)
-      except:
+      except Exception:
         pass
         pass
 
 
     # Return
     # Return

+ 1 - 1
zz_remux/zz_remux/scan.py

@@ -44,7 +44,7 @@ class Scan:
         try:
         try:
           lang = langcodes.Language.get(m.group(2).lower())
           lang = langcodes.Language.get(m.group(2).lower())
           info['lang'] = lang.to_alpha3()
           info['lang'] = lang.to_alpha3()
-        except:
+        except Exception:
           if m.group(2):
           if m.group(2):
             self.logger.warning(f"Unable to match language code: {m.group(2)}")
             self.logger.warning(f"Unable to match language code: {m.group(2)}")
 
 

+ 2 - 2
zz_remux/zz_remux/tag.py

@@ -14,7 +14,7 @@ class Tag:
     if ret:
     if ret:
       try:
       try:
         ret = int.from_bytes(ret)
         ret = int.from_bytes(ret)
-      except:
+      except Exception:
         self.logger.error(f"Unable to decode int ({path}): {attr} => {ret}")
         self.logger.error(f"Unable to decode int ({path}): {attr} => {ret}")
     return ret
     return ret
 
 
@@ -23,7 +23,7 @@ class Tag:
     if ret:
     if ret:
       try:
       try:
         ret = ret.decode(self._encoding)
         ret = ret.decode(self._encoding)
-      except:
+      except Exception:
         self.logger.error(f"Unable to decode str ({path}): {attr} => {ret}")
         self.logger.error(f"Unable to decode str ({path}): {attr} => {ret}")
     return ret
     return ret