{"record":{"id":"6530f116013f0632","repo":"earendil-works/pi","slug":"frame-must-be-a-uint8array","errorCode":null,"errorMessage":"Frame must be a Uint8Array","messagePattern":"Frame must be a Uint8Array","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/protocol/src/framing.ts","lineNumber":43,"sourceCode":"}\n\n/** Prefixes a payload with its unsigned 32-bit big-endian byte length. */\nexport function encodeFrame(payload: Uint8Array): Uint8Array {\n\tif (!(payload instanceof Uint8Array)) throw new TypeError(\"Frame payload must be a Uint8Array\");\n\tif (payload.byteLength > MAX_UINT32) throw new RangeError(\"Frame payload exceeds the unsigned 32-bit length limit\");\n\tconst frame = new Uint8Array(FRAME_HEADER_LENGTH + payload.byteLength);\n\tconst length = payload.byteLength;\n\tframe[0] = length >>> 24;\n\tframe[1] = length >>> 16;\n\tframe[2] = length >>> 8;\n\tframe[3] = length;\n\tframe.set(payload, FRAME_HEADER_LENGTH);\n\treturn frame;\n}\n\n/** Validates that bytes contain exactly one complete frame within the configured limit. */\nexport function assertCompleteFrame(frame: Uint8Array, options?: FrameDecoderOptions): void {\n\tif (!(frame instanceof Uint8Array)) throw new TypeError(\"Frame must be a Uint8Array\");\n\tif (frame.byteLength < FRAME_HEADER_LENGTH) throw new FrameError(\"Frame does not contain a complete length prefix\");\n\tconst length = frame[0]! * 0x1_000_000 + frame[1]! * 0x1_0000 + frame[2]! * 0x100 + frame[3]!;\n\tconst maxFrameLength = resolveMaxFrameLength(options);\n\tif (length > maxFrameLength) {\n\t\tthrow new FrameError(`Frame length ${length} exceeds configured limit of ${maxFrameLength}`);\n\t}\n\tif (frame.byteLength !== FRAME_HEADER_LENGTH + length) {\n\t\tthrow new FrameError(\"Frame must contain exactly one complete payload\");\n\t}\n}\n\ntype DecoderState = \"open\" | \"ended\" | \"failed\";\n\n/** Incrementally splits arbitrary byte chunks into length-prefixed payloads. */\nexport class FrameDecoder {\n\tprivate readonly header = new Uint8Array(FRAME_HEADER_LENGTH);\n\tprivate headerLength = 0;\n\tprivate readonly maxFrameLength: number;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/protocol/src/framing.ts#L25-L61","documentation":"Error \"Frame must be a Uint8Array\" thrown in earendil-works/pi.","triggerScenarios":"Thrown at packages/protocol/src/framing.ts:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the frame as a Uint8Array."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}