Handle invalid UTF-8 with replacement decoding

This commit is contained in:
jxxghp
2026-06-21 09:56:34 +08:00
parent 99e369aaa4
commit 68f18db374
29 changed files with 139 additions and 121 deletions
+3 -3
View File
@@ -343,7 +343,7 @@ class SkillHelper(metaclass=WeakSingleton):
if not meta_path.exists():
return {}
try:
payload = json.loads(meta_path.read_text(encoding="utf-8"))
payload = json.loads(meta_path.read_text(encoding="utf-8", errors="replace"))
return payload if isinstance(payload, dict) else {}
except Exception as e:
logger.warning("读取技能来源元数据失败:%s - %s", meta_path, e)
@@ -381,7 +381,7 @@ class SkillHelper(metaclass=WeakSingleton):
if not skill_md.exists():
continue
try:
content = skill_md.read_text(encoding="utf-8")
content = skill_md.read_text(encoding="utf-8", errors="replace")
except Exception as e:
logger.warning("读取技能文件失败:%s - %s", skill_md, e)
continue
@@ -979,7 +979,7 @@ class SkillHelper(metaclass=WeakSingleton):
content = getattr(response, "content", b"")
if isinstance(content, bytes):
return content.decode("utf-8", errors="ignore")
return content.decode("utf-8", errors="replace")
if isinstance(content, str):
return content
return ""