{"record":{"id":"1760e2d73101c731","repo":"linshenkx/prompt-optimizer","slug":"desktop-remote-storage-returned-an-unsupported-bin","errorCode":null,"errorMessage":"Desktop remote storage returned an unsupported binary payload","messagePattern":"Desktop remote storage returned an unsupported binary payload","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/utils/remote-backup.ts","lineNumber":656,"sourceCode":"  if (body instanceof ArrayBuffer) return new Uint8Array(body.slice(0))\n  if (body instanceof Blob) return new Uint8Array(await body.arrayBuffer())\n  return new Uint8Array(0)\n}\n\nconst copyUint8ArrayToArrayBuffer = (bytes: Uint8Array): ArrayBuffer => {\n  const view = new Uint8Array(bytes.byteLength)\n  view.set(bytes)\n  return view.buffer\n}\n\nconst ipcBytesToArrayBuffer = (value: unknown): ArrayBuffer => {\n  if (value instanceof ArrayBuffer) return value.slice(0)\n  if (value instanceof Uint8Array) return copyUint8ArrayToArrayBuffer(value)\n  if (ArrayBuffer.isView(value)) {\n    return copyUint8ArrayToArrayBuffer(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))\n  }\n  if (Array.isArray(value)) return copyUint8ArrayToArrayBuffer(new Uint8Array(value))\n  throw new Error('Desktop remote storage returned an unsupported binary payload')\n}\n\nconst s3BodyToArrayBuffer = async (body: unknown): Promise<ArrayBuffer> => {\n  if (!body) return new ArrayBuffer(0)\n  if (body instanceof ArrayBuffer) return body\n  if (body instanceof Uint8Array) return copyUint8ArrayToArrayBuffer(body)\n  if (body instanceof Blob) return body.arrayBuffer()\n\n  const withArrayBuffer = body as { arrayBuffer?: () => Promise<ArrayBuffer> }\n  if (typeof withArrayBuffer.arrayBuffer === 'function') {\n    return withArrayBuffer.arrayBuffer()\n  }\n\n  const withByteArray = body as { transformToByteArray?: () => Promise<Uint8Array> }\n  if (typeof withByteArray.transformToByteArray === 'function') {\n    return copyUint8ArrayToArrayBuffer(await withByteArray.transformToByteArray())\n  }\n","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/utils/remote-backup.ts#L638-L674","documentation":"Thrown by the desktop remote storage binary coercion helper when the payload returned from the desktop (Electron/Tauri IPC) remote storage layer is not one of the recognized binary types (ArrayBuffer, Uint8Array, other typed-array views, or byte array). It guards against structured-clone IPC returning unexpected shapes before backup processing continues.","triggerScenarios":"Desktop IPC bridge returning a Node Buffer-like object, Blob, plain object, string base64, or null-ish non-empty value that is not a view or array; serialization settings (e.g. ipcRenderer invoking with no ArrayBuffer transfer, or contextIsolation serialization) mangling binary data.","commonSituations":"Electron IPC serializing ArrayBuffers to something else when the handler forgets to copy/convert; desktop bridge version mismatch where the payload format changed (e.g. base64 string instead of bytes); Node Buffer passed directly (is a Uint8Array subclass but crossing a serialization boundary that strips it).","solutions":["Update the desktop app / IPC bridge so it returns ArrayBuffer or Uint8Array for binary payloads","Convert the payload in the desktop handler before returning: buffer.buffer.slice(...) or new Uint8Array(buffer)","Align desktop shell and UI package versions so the binary contract matches","Log the actual value's constructor/type at the boundary to identify the mangling layer"],"exampleFix":"// desktop preload/handler: before\nipcMain.handle('read-backup', async (_e, id) => fs.readFile(path)) // returns Buffer-ish\n// after\nipcMain.handle('read-backup', async (_e, id) => {\n  const buf = await fs.readFile(path)\n  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength) // ArrayBuffer\n})","handlingStrategy":"type-guard","validationCode":"const isSupportedBinary = (v: unknown): boolean =>\n  v instanceof ArrayBuffer || v instanceof Uint8Array || ArrayBuffer.isView(v) || Array.isArray(v)","typeGuard":"const isDesktopBinaryPayload = (v: unknown): v is ArrayBuffer | Uint8Array =>\n  v instanceof ArrayBuffer || v instanceof Uint8Array","tryCatchPattern":"try {\n  await readRemoteBinary(...)\n} catch (error) {\n  if ((error as Error).message.includes('unsupported binary payload')) {\n    // desktop bridge contract broken: prompt user to update the desktop app\n    notifyDesktopUpdateRequired()\n  }\n}","preventionTips":["Pin desktop shell and UI package to matching versions","Always return ArrayBuffer from IPC handlers (never raw Node Buffer)","Add a version handshake between UI and desktop bridge at startup"],"tags":["desktop-ipc","binary-data","serialization","remote-backup"],"backgroundTag":"ipc-payload-type-mismatch","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}