3
0
Просмотр исходного кода

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 месяцев назад
Родитель
Сommit
bab235346f

+ 2 - 2
zz_remux/zz_remux/cli.py

@@ -28,7 +28,7 @@ def main():
   args = None
   try:
     args = parser.parse_args()
-  except:
+  except Exception:
     parser.print_help()
     sys.exit(-1)
   if args.debug:
@@ -47,7 +47,7 @@ def main():
     try:
       match = re.compile(args.match, re.IGNORECASE)
       args.match = True
-    except:
+    except Exception:
       print(f"Unable to compile match regex: {args.match}", file=sys.stderr)
       parser.print_help()
       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}")
           source['path'].unlink()
           media.remove(source)
-      except BaseException as e:
+      except Exception as e:
         self.logger.error(f"Unlink error: {e}")
         continue
 
@@ -120,7 +120,7 @@ class Mux:
         info['group']    = videos[0]['group']
         info['mux_vers'] = Consts.mux_vers
         media.append(info)
-      except BaseException as e:
+      except Exception as e:
         err = e
       if not final.exists():
         err = 'file missing'

+ 1 - 1
zz_remux/zz_remux/probe.py

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

+ 3 - 3
zz_remux/zz_remux/proc.py

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

+ 1 - 1
zz_remux/zz_remux/scan.py

@@ -44,7 +44,7 @@ class Scan:
         try:
           lang = langcodes.Language.get(m.group(2).lower())
           info['lang'] = lang.to_alpha3()
-        except:
+        except Exception:
           if 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:
       try:
         ret = int.from_bytes(ret)
-      except:
+      except Exception:
         self.logger.error(f"Unable to decode int ({path}): {attr} => {ret}")
     return ret
 
@@ -23,7 +23,7 @@ class Tag:
     if ret:
       try:
         ret = ret.decode(self._encoding)
-      except:
+      except Exception:
         self.logger.error(f"Unable to decode str ({path}): {attr} => {ret}")
     return ret