Sanitize, then hard-cap the serialized size of one entry's detail.
(value: unknown)
| 139 | |
| 140 | /** Sanitize, then hard-cap the serialized size of one entry's detail. */ |
| 141 | function detailOf(value: unknown): unknown { |
| 142 | if (value === undefined) return undefined; |
| 143 | const sanitized = sanitizeForTrace(value); |
| 144 | try { |
| 145 | const json = JSON.stringify(sanitized); |
| 146 | if (json !== undefined && json.length > MAX_DETAIL_JSON_CHARS) { |
| 147 | return { |
| 148 | _truncated: `detail JSON was ${json.length} chars; first ${MAX_DETAIL_JSON_CHARS} kept`, |
| 149 | preview: json.slice(0, MAX_DETAIL_JSON_CHARS), |
| 150 | }; |
| 151 | } |
| 152 | } catch { |
| 153 | return '[unserializable detail]'; |
| 154 | } |
| 155 | return sanitized; |
| 156 | } |
| 157 | |
| 158 | // --------------------------------------------------------------------------- |
| 159 | // REST recording — called from DaemonHttpClient |
no test coverage detected