Skip to content

Commit 7bbd041

Browse files
lsr911claude
andcommitted
fix(logging): use truncateUtf16Safe in diagnostic stability and session context
Replace naive .slice(0, N) with truncateUtf16Safe() in: - diagnostic-stability-bundle.ts: error message sanitization - diagnostic-session-context.ts: quoted field value truncation Co-Authored-By: Claude <[email protected]>
1 parent 32de666 commit 7bbd041

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/logging/diagnostic-session-context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Diagnostic session context helpers capture session metadata for support bundles.
22
import fs from "node:fs";
33
import path from "node:path";
4+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
45
import { resolveStateDir } from "../config/paths.js";
56
import { loadCronJobsStoreSync, resolveCronJobsStorePath } from "../cron/store.js";
67

@@ -19,7 +20,7 @@ function quoteLogField(value: string): string {
1920
const oneLine = value.replace(/\s+/g, " ").trim();
2021
const truncated =
2122
oneLine.length > MAX_QUOTED_FIELD_CHARS
22-
? `${oneLine.slice(0, Math.max(0, MAX_QUOTED_FIELD_CHARS - 3))}...`
23+
? `${truncateUtf16Safe(oneLine, Math.max(0, MAX_QUOTED_FIELD_CHARS - 3))}...`
2324
: oneLine;
2425
return `"${truncated.replace(/["\\]/g, "\\$&")}"`;
2526
}

src/logging/diagnostic-stability-bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Diagnostic stability bundle helpers collect stable diagnostic data for comparison.
22
import fs from "node:fs";
33
import path from "node:path";
4+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
45
import process from "node:process";
56
import v8 from "node:v8";
67
import { resolveStateDir } from "../config/paths.js";
@@ -207,7 +208,7 @@ function readErrorMessage(error: unknown): string | undefined {
207208
return undefined;
208209
}
209210
return sanitized.length > MAX_SAFE_ERROR_MESSAGE_LENGTH
210-
? `${sanitized.slice(0, MAX_SAFE_ERROR_MESSAGE_LENGTH)}...`
211+
? `${truncateUtf16Safe(sanitized, MAX_SAFE_ERROR_MESSAGE_LENGTH)}...`
211212
: sanitized;
212213
}
213214

0 commit comments

Comments
 (0)