diff --git a/scripts/daemon.py b/scripts/daemon.py index 6400b8a5..110c65f2 100755 --- a/scripts/daemon.py +++ b/scripts/daemon.py @@ -399,7 +399,7 @@ def save_llm_context(ctx, state): data = json.load(f) for c in data.get("queue", []): cares.append({"id": c.get("id", ""), "content": c.get("content", "")[:60], "due": c.get("due_date", "")}) - except Exception: + except (json.JSONDecodeError, OSError, IOError, KeyError, TypeError): pass # 读心迹(最近3条,直接读 jsonl) @@ -412,7 +412,7 @@ def save_llm_context(ctx, state): if line.strip(): e = json.loads(line) recent_moments.append({"content": e["content"][:80], "importance": e.get("importance", 0), "timestamp": e.get("timestamp", "")}) - except Exception: + except (json.JSONDecodeError, OSError, IOError, KeyError, TypeError): pass # 读画像(user-profile.json 最新行) @@ -421,7 +421,7 @@ def save_llm_context(ctx, state): if os.path.exists(profile_path): try: profile = json.load(open(profile_path, encoding="utf-8")) - except Exception: + except (json.JSONDecodeError, OSError, IOError, KeyError, TypeError): pass # os_sense @@ -431,7 +431,7 @@ def save_llm_context(ctx, state): try: kw = json.load(open(os_path, encoding="utf-8")).get("keywords", []) os_keywords = kw if isinstance(kw, list) else [] - except Exception: + except (json.JSONDecodeError, OSError, IOError, KeyError, TypeError): pass llm_ctx = { diff --git a/scripts/soulful_core.py b/scripts/soulful_core.py index 2b3ebcb7..67d39631 100644 --- a/scripts/soulful_core.py +++ b/scripts/soulful_core.py @@ -54,7 +54,7 @@ def _zhiyi_commit(content: str, category: str = "episodes", importance: int = 3) if r.status_code in (200, 201): data = r.json() return data.get("episode_id") or data.get("commit_id") - except Exception: + except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.RequestException, OSError, IOError): pass return None