fix(doctor): keep scrubbed error truncation UTF-16 safe (#102066)

* fix(doctor): keep scrubbed error truncation UTF-16 safe

* test(doctor): assert exact scrubbed error output

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
mushuiyu886
2026-07-09 04:39:15 +01:00
committed by GitHub
co-authored by Peter Steinberger
parent b62c796e51
commit 7daa090935
2 changed files with 16 additions and 1 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
// Shared sanitization for doctor/lint/repair errors shown in terminal output.
const ERR_MESSAGE_MAX_LEN = 256;
@@ -14,5 +16,5 @@ export function scrubDoctorErrorMessage(err: unknown): string {
if (stripped.length <= ERR_MESSAGE_MAX_LEN) {
return stripped;
}
return `${stripped.slice(0, ERR_MESSAGE_MAX_LEN - 3)}...`;
return `${truncateUtf16Safe(stripped, ERR_MESSAGE_MAX_LEN - 3)}...`;
}
+13
View File
@@ -135,6 +135,19 @@ describe("runDoctorLintChecks", () => {
},
]);
});
it("keeps truncated thrown error messages UTF-16 safe", async () => {
const emoji = "\u{1F600}";
const result = await runDoctorLintChecks(ctx, {
checks: [
check("emoji-boom", async () => {
throw new Error(`${"A".repeat(252)}${emoji}${"B".repeat(10)}`);
}),
],
});
expect(result.findings[0]?.message).toBe(`health check threw: ${"A".repeat(252)}...`);
});
});
describe("exitCodeFromFindings", () => {