Skip to content

Commit 87ea557

Browse files
committed
refactor(codex): unify app inventory error truncation
1 parent 5bee7e6 commit 87ea557

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

extensions/codex/src/app-server/app-inventory-cache.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ function fingerprintInventoryCacheKey(key: string): string {
338338
return hash.toString(16).padStart(8, "0");
339339
}
340340

341+
function truncateSerializedErrorText(value: string): string {
342+
return value.length > MAX_SERIALIZED_ERROR_MESSAGE_LENGTH
343+
? `${truncateUtf16Safe(value, MAX_SERIALIZED_ERROR_MESSAGE_LENGTH)}...`
344+
: value;
345+
}
346+
341347
function redactErrorData(value: unknown, depth = 0): JsonValue | undefined {
342348
if (value === undefined) {
343349
return undefined;
@@ -360,11 +366,8 @@ function redactErrorData(value: unknown, depth = 0): JsonValue | undefined {
360366
}
361367
return redacted;
362368
}
363-
if (typeof value === "string" && value.length > 500) {
364-
return `${truncateUtf16Safe(value, 500)}...`;
365-
}
366369
if (typeof value === "string") {
367-
return value;
370+
return truncateSerializedErrorText(value);
368371
}
369372
if (typeof value === "bigint") {
370373
return value.toString();
@@ -388,9 +391,7 @@ function sanitizeErrorMessage(message: string): string {
388391
/([?&][^=\s"'<>]*(?:api[_-]?key|authorization|cookie|credential|password|secret|token|tk)[^=\s"'<>]*=)[^&\s"'<>]+/gi,
389392
"$1<redacted>",
390393
);
391-
return redacted.length > MAX_SERIALIZED_ERROR_MESSAGE_LENGTH
392-
? `${truncateUtf16Safe(redacted, MAX_SERIALIZED_ERROR_MESSAGE_LENGTH)}...`
393-
: redacted;
394+
return truncateSerializedErrorText(redacted);
394395
}
395396

396397
function isSensitiveErrorDataKey(key: string): boolean {

0 commit comments

Comments
 (0)