diff --git a/apps/import/routes.py b/apps/import/routes.py index 6eadafffa..1e58afeb9 100644 --- a/apps/import/routes.py +++ b/apps/import/routes.py @@ -4,6 +4,7 @@ from __future__ import annotations import json +import logging import re import time from pathlib import Path @@ -290,8 +291,8 @@ def import_save() -> Any: "entry_count": existing.get("entry_count", 0), "import_id": existing.get("import_id", ""), } - except Exception: - pass # dedup check is best-effort + except OSError as exc: + logging.warning("Dedup check failed for %s: %s", file_path, exc) result: dict[str, Any] = { "path": str(file_path), diff --git a/apps/settings/routes.py b/apps/settings/routes.py index a8d9d54b5..104b520aa 100644 --- a/apps/settings/routes.py +++ b/apps/settings/routes.py @@ -1671,8 +1671,8 @@ def _get_logs_from_dir(logs_dir: Path, cursor: str | None) -> dict: line = line.strip() if line: entries.append(json.loads(line)) - except Exception: - pass + except (OSError, json.JSONDecodeError) as exc: + logger.warning("Failed to read settings log %s: %s", target_file, exc) # Reverse to show newest first within the day entries.reverse() diff --git a/apps/sol/routes.py b/apps/sol/routes.py index d2cbdd3f6..f0a1ab05a 100644 --- a/apps/sol/routes.py +++ b/apps/sol/routes.py @@ -6,6 +6,7 @@ from __future__ import annotations import json +import logging import re from datetime import date, datetime from functools import lru_cache @@ -290,8 +291,8 @@ def _get_uses_for_day(day: str, facet_filter: str | None = None) -> list[dict]: use_info = _parse_use_file(use_file) if use_info: uses.append(use_info) - except IOError: - pass + except OSError as exc: + logging.warning("Failed to read use day index %s: %s", day_index_path, exc) # Also check for running uses (only have _active files, no day index entry yet) for use_file in talents_dir.glob("*/*_active.jsonl"): diff --git a/think/cortex.py b/think/cortex.py index 967b651fd..5daa112e8 100644 --- a/think/cortex.py +++ b/think/cortex.py @@ -603,10 +603,19 @@ class CortexService: event = json.loads(line) if event.get("event") in ["finish", "error"]: return True - except json.JSONDecodeError: + except json.JSONDecodeError as exc: + self.logger.warning( + "Malformed event in %s while scanning for finish: %s", + file_path, + exc, + ) continue - except Exception: - pass + except FileNotFoundError: + self.logger.debug("Use log disappeared before finish scan: %s", file_path) + except OSError as exc: + self.logger.warning( + "Failed to scan %s for finish events: %s", file_path, exc + ) return False def _complete_use_file(self, use_id: str, file_path: Path) -> None: diff --git a/think/dream.py b/think/dream.py index 42972d15d..bfd87c412 100644 --- a/think/dream.py +++ b/think/dream.py @@ -69,8 +69,8 @@ class DreamJSONLWriter: try: Path(path).parent.mkdir(parents=True, exist_ok=True) self.file = open(path, "a", encoding="utf-8") - except Exception: - pass + except OSError as exc: + logging.warning("Failed to open dream JSONL sidecar %s: %s", path, exc) def log(self, event: str, **fields) -> None: if not self.file: @@ -81,15 +81,19 @@ class DreamJSONLWriter: try: self.file.write(json.dumps(data, ensure_ascii=False) + "\n") self.file.flush() - except Exception: - pass + except OSError as exc: + logging.warning( + "Failed to write dream JSONL sidecar %s: %s", self.file.name, exc + ) def close(self) -> None: if self.file: try: self.file.close() - except Exception: - pass + except OSError as exc: + logging.warning( + "Failed to close dream JSONL sidecar %s: %s", self.file.name, exc + ) _jsonl: DreamJSONLWriter | None = None diff --git a/think/facets.py b/think/facets.py index 7fc299c61..52e472f85 100644 --- a/think/facets.py +++ b/think/facets.py @@ -243,8 +243,11 @@ def get_facets() -> dict[str, dict[str, object]]: } facets[facet_name] = facet_info - except Exception as exc: # pragma: no cover - metadata optional - logging.debug("Error reading %s: %s", facet_json, exc) + except ( + OSError, + json.JSONDecodeError, + ) as exc: # pragma: no cover - metadata optional + logging.warning("Failed to read facet metadata %s: %s", facet_json, exc) return facets diff --git a/think/talents.py b/think/talents.py index 3b0db8257..6cf09e5de 100644 --- a/think/talents.py +++ b/think/talents.py @@ -75,8 +75,8 @@ class JSONEventWriter: try: Path(path).parent.mkdir(parents=True, exist_ok=True) self.file = open(path, "a", encoding="utf-8") - except Exception: - pass # Fail silently if can't open file + except OSError as exc: + LOG.warning("Failed to open JSON event sidecar %s: %s", path, exc) def emit(self, data: Event) -> None: line = json.dumps(data, ensure_ascii=False) @@ -86,15 +86,15 @@ class JSONEventWriter: try: self.file.write(line + "\n") self.file.flush() - except Exception: - pass # Fail silently on write errors + except OSError as exc: + LOG.warning("Failed to write JSON event sidecar %s: %s", self.path, exc) def close(self) -> None: if self.file: try: self.file.close() - except Exception: - pass + except OSError as exc: + LOG.warning("Failed to close JSON event sidecar %s: %s", self.path, exc) # =============================================================================