fix: tighten exception handling in daemon.py, soulful_core.py, zhiyi/__init__.py
- daemon.py: replace bare 'except Exception: pass' with specific (json.JSONDecodeError, OSError, IOError, KeyError, TypeError) in save_llm_context() — all 4 locations - soulful_core.py: replace bare Exception in _zhiyi_commit with (requests.exceptions.Timeout, ConnectionError, RequestException, OSError, IOError); note ZHIYI_TIMEOUT=3 kept unchanged - zhiyi/__init__.py: replace bare Exception in _load_soulful_context with (json.JSONDecodeError, OSError, IOError, KeyError, TypeError) All files verified: python3 -m py_compile OK
This commit is contained in:
parent
36ec8dc9fd
commit
61d2ab09c6
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue