Skip to content

Commit 79efa80

Browse files
committed
fix(diagnostics-prometheus): use truncateUtf16Safe for error message truncation
The safeErrorMessage function uses naive .slice(0, 500) on error messages which can split surrogate pairs. Replace with truncateUtf16Safe().
1 parent 9566ade commit 79efa80

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

extensions/diagnostics-prometheus/src/service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Diagnostics Prometheus plugin module implements service behavior.
22
import type { IncomingMessage, ServerResponse } from "node:http";
3+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
34
import type {
45
DiagnosticEventMetadata,
56
DiagnosticEventPayload,
@@ -228,10 +229,12 @@ function createPrometheusMetricStore() {
228229

229230
function safeErrorMessage(err: unknown): string {
230231
const message = err instanceof Error ? (err.message ?? err.name) : String(err);
231-
return redactSensitiveText(message)
232-
.replaceAll("\u0000", " ")
233-
.replace(/[\r\n\t\u2028\u2029]/gu, " ")
234-
.slice(0, 500);
232+
return truncateUtf16Safe(
233+
redactSensitiveText(message)
234+
.replaceAll("\u0000", " ")
235+
.replace(/[\r\n\t\u2028\u2029]/gu, " "),
236+
500,
237+
);
235238
}
236239

237240
function shouldRecordDiagnosticEvent(metadata: DiagnosticEventMetadata): boolean {

0 commit comments

Comments
 (0)