fix(quality): say why each empty except is safe, log the broad ones

This commit is contained in:
Vito Sansevero
2026-10-30 21:43:32 -07:00
parent f71dff2fc9
commit 643a055381
21 changed files with 34 additions and 4 deletions
+3
View File
@@ -120,6 +120,7 @@ except Exception as e:
logger = get_logger("prompt_manager.init")
logger.error(f"Failed to register API routes: {e}")
except Exception:
# logging failed too; a report must never stop the node loading
pass
# Shared database, set up with the monitoring system below. Stays None when that
@@ -411,6 +412,7 @@ except Exception as e:
f"Failed to register the exit signal: {e}"
)
except Exception:
# logging failed too; a report must never stop the node loading
pass
try:
@@ -428,6 +430,7 @@ except Exception as e:
f"Failed to register the background work teardown: {e}"
)
except Exception:
# logging failed too; a report must never stop the node loading
pass
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
+1
View File
@@ -590,6 +590,7 @@ class _Move:
try:
os.rmdir(self.plan.target_dir)
except OSError:
# not empty or already gone: the undo leaves it alone
pass
+1
View File
@@ -46,6 +46,7 @@ def remove_quietly(*paths):
if path and os.path.exists(path):
os.remove(path)
except OSError:
# cleanup after a failure must not replace that failure
pass
+1
View File
@@ -539,6 +539,7 @@ def _diagnose_output_dirs(configured_dirs, public_path=None):
candidates.append(folder_paths.get_output_directory())
except ImportError:
# outside ComfyUI there is no output folder to add
pass
output_dirs = []
+2
View File
@@ -396,6 +396,7 @@ def _video_placeholder_image(thumbnail_size):
font=font,
)
except (OSError, AttributeError):
# a placeholder without its label still works
pass
return img
@@ -499,6 +500,7 @@ def _preview_names(folders, folder):
except OSError:
continue
except OSError:
# an unreadable folder lists as empty; nothing there to cache
pass
folders[folder] = names
return names
+1
View File
@@ -207,6 +207,7 @@ class LibraryLocationRoutesMixin:
try:
size = os.path.getsize(location.db_path)
except OSError:
# no library file yet: report size 0
pass
return {
"path": self._library_public_path(location.db_path),
+1
View File
@@ -536,6 +536,7 @@ class LoraIntegrationMixin:
except asyncio.CancelledError:
interrupted = True
except Exception:
# the await after this loop raises it for the caller
pass
if interrupted:
raise asyncio.CancelledError
+1
View File
@@ -533,6 +533,7 @@ class AutoThumbnailer:
try:
process.kill()
except OSError:
# the process has already exited
pass
if worker is None:
return True
+4
View File
@@ -158,6 +158,7 @@ def _unlink_quietly(path):
try:
Path(path).unlink()
except FileNotFoundError:
# already gone, which is what was wanted
pass
except OSError as exc:
logger.debug(f"Could not remove temp file {Path(path).name}: {exc}")
@@ -221,6 +222,7 @@ def shutdown_encoders():
try:
process.kill()
except OSError:
# the process has already exited
pass
@@ -359,10 +361,12 @@ def thumbnail_frame(img, edge):
try:
img.seek(0)
except (EOFError, AttributeError, ValueError):
# not seekable or a single frame: use the current one
pass
try:
img.draft("RGB", (edge, edge)) # JPEG: decode at a reduced scale
except (AttributeError, ValueError, OSError):
# draft is only a speedup; the full decode below still works
pass
frame = img.convert("RGB") if img.mode != "RGB" else img.copy()
frame.thumbnail((edge, edge), Image.Resampling.LANCZOS)
+1
View File
@@ -109,6 +109,7 @@ def _write_atomically(path: str, payload: bytes) -> None:
try:
os.unlink(temp_path)
except OSError:
# nothing to clean up; the original error is raised below
pass
raise
+1
View File
@@ -642,6 +642,7 @@ def layout_summary(layout: LoraManagerLayout, home: Path) -> Dict:
relative = Path(settings_file).relative_to(home)
settings_file = os.path.join("~", str(relative))
except ValueError:
# outside the home folder: show the full path
pass
return {
"source": layout.source,
+2
View File
@@ -585,6 +585,7 @@ def _read_capped(resp, cap: int) -> Optional[bytes]:
if int(declared) > cap:
return None
except ValueError:
# a bad header says nothing; the read below enforces the cap
pass
chunks = []
@@ -707,6 +708,7 @@ def _save_atomically(image, local_path: Path) -> None:
try:
os.remove(temp)
except OSError:
# nothing to clean up; the original error is raised below
pass
raise
+1
View File
@@ -109,6 +109,7 @@ class ResetWatch:
stream.write(text)
stream.flush()
except (OSError, ValueError):
# the stream closed; a watcher must not fail the server
pass
+1
View File
@@ -135,6 +135,7 @@ class TestLogsAndCache(_EnvCase):
get_logger_manager()._setup_loggers()
except Exception:
# best effort restore in teardown; must not hide the test result
pass
def test_lora_image_cache_follows_the_data_folder(self):
+1
View File
@@ -398,6 +398,7 @@ class HistoryWriter:
try:
command = self._queue.get_nowait()
except queue.Empty:
# no command waiting; the loop below handles command None
pass
if probe:
try:
+4 -4
View File
@@ -1048,8 +1048,8 @@ class ImageGenerationHandler(FileSystemEventHandler):
with Image.open(image_path) as img:
file_info["dimensions"] = list(img.size)
file_info["format"] = img.format
except Exception:
pass
except Exception as error:
self.logger.debug(f"No dimensions for {image_path}: {error}")
return file_info
except Exception as e:
@@ -1424,8 +1424,8 @@ class ImageMonitor:
if self.observer is not None:
try:
observer_alive = self.observer.is_alive()
except Exception:
pass
except Exception as error:
self.logger.debug(f"Could not read the observer state: {error}")
return {
"running": self.observer is not None,
"monitored_directories": self.monitored_directories,
+1
View File
@@ -466,6 +466,7 @@ def ensure_private_dir(path: str) -> str:
try:
os.chmod(path, 0o700)
except OSError:
# the folder exists; a filesystem without modes keeps its own
pass
return path
+2
View File
@@ -181,6 +181,7 @@ def _unlink_quietly(path: str) -> None:
try:
os.unlink(path)
except FileNotFoundError:
# already gone, which is what was wanted
pass
except OSError as error:
logger.warning("Capture file %s could not be removed: %s", path, error)
@@ -390,6 +391,7 @@ class CaptureStore:
try:
os.rmdir(self.directory)
except FileNotFoundError:
# already gone, which is what was wanted
pass
except OSError as error:
logger.warning(
+1
View File
@@ -339,6 +339,7 @@ class FreedesktopBackend:
try:
os.mkdir(name, 0o700, dir_fd=parent_fd)
except FileExistsError:
# the folder already exists; the checks below still vet it
pass
except OSError as error:
raise TrashRefused(NO_TRASH, str(error)) from error
+1
View File
@@ -114,6 +114,7 @@ def inside_any_root(path: str, roots) -> bool:
if _identity(current) in identities:
return True
except OSError:
# an unreadable folder cannot be a trash; try its parent
pass
parent = os.path.dirname(current)
if parent == current:
+3
View File
@@ -88,6 +88,7 @@ def _unlink(path: str) -> None:
try:
os.unlink(path)
except OSError:
# best effort cleanup; the next sweep removes a leftover temp
pass
@@ -105,6 +106,7 @@ def _sweep_temps(directory: str) -> None:
if os.stat(path).st_mtime < cutoff:
os.unlink(path)
except OSError:
# best effort: a later sweep removes what this one could not
pass
@@ -116,6 +118,7 @@ def _tighten(path: str) -> None:
if stat.S_IMODE(os.stat(path).st_mode) & 0o077:
os.chmod(path, 0o600)
except OSError:
# best effort: the key still works with its old mode
pass