Repository navigation
Replies: 2 comments
0 replies
补充:这个可以直接修,不用每次清文件给维护者一个更省事的路径:根因在读取函数,补三层就够。 定位profile manifest 的读取函数 raw = readFileSync(path, "utf8");
const parsed = JSON.parse(raw); // ← BOM 在这里炸
建议补丁(约 8 行)raw = readFileSync(path, "utf8");
const text = raw.charCodeAt(0) === 0xFEFF ? raw.slice(1) : raw;
let parsed;
try {
parsed = JSON.parse(text);
} catch (error) {
throw new Error(
`${binName}: profile manifest ${path} is not valid JSON (${String(error)}). ` +
`If the file begins with a UTF-8 BOM (EF BB BF), rewrite it as UTF-8 without BOM.`,
);
}
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
throw new Error(`${binName}: profile manifest ${path} must hold a JSON object`);
}最小复现
建议补的单测
为什么只清文件不够上面那条清理脚本只能救已经损坏的文件;只要写侧(PowerShell 脚本、部分编辑器"另存为 UTF-8"、第三方安装脚本)再来一次带 BOM 写入,同一个崩溃就会复现——用户很难自查到是 BOM 的问题。 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
环境
现象
~/.dsh/profiles/desktop/package.json含 UTF-8 BOM(EF BB BF)时,重启 DSH Desktop 直接启动崩溃,无法进入界面:崩溃日志:
%APPDATA%\@deepseek-ai\dsh-desktop\logs\crash-<ts>-host.log复现步骤
Set-Content -Encoding UTF8写~/.dsh/profiles/desktop/package.json(该编码会在文件头写入 BOM);期望
正常启动;或至少给出「profile manifest 含 BOM,请移除」这类可读错误,而不是直接崩掉。
根因
启动时
readProfileManifest直接对文件内容调用JSON.parse,未剥离 UTF-8 BOM。BOM 是合法的字节序标记,但JSON.parse会把它当非法字符抛异常,导致初始化失败。不止手改文件会触发:PowerShell 5.1、部分编辑器「另存为 UTF-8」、以及某些第三方插件/安装脚本都会写出带 BOM 的 JSON,用户很难自查。
建议修复
text.replace(/^\uFEFF/, ''),或使用 BOM-aware 读取方式;临时规避
备份后去掉文件头 3 字节
EF BB BF,用无 BOM UTF-8 重写即可恢复:All reactions