Encodes an error message payload, truncated to a bounded length.
(error: unknown)
| 61 | |
| 62 | /** Encodes an error message payload, truncated to a bounded length. */ |
| 63 | function encodeErrorPayload(error: unknown): Uint8Array { |
| 64 | const originalMessage = |
| 65 | error instanceof Error ? error.message : String(error ?? 'Unknown error') |
| 66 | const message = |
| 67 | originalMessage.length > MAX_ERROR_MESSAGE_CODE_UNITS |
| 68 | ? `${originalMessage.slice(0, MAX_ERROR_MESSAGE_CODE_UNITS)}…` |
| 69 | : originalMessage |
| 70 | return textEncoder.encode(message) |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Late stream registration for RawStreams discovered after serialization starts. |