{"record":{"id":"fc83740cd0af85f2","repo":"linshenkx/prompt-optimizer","slug":"invalid-favorite-share-payload","errorCode":null,"errorMessage":"Invalid favorite share payload","messagePattern":"Invalid favorite share payload","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/utils/favorite-share-export.ts","lineNumber":1440,"sourceCode":"  const textBytes = data.slice(offset)\n  try {\n    return compressionFlag === 1\n      ? strFromU8(unzlibSync(textBytes))\n      : strFromU8(textBytes)\n  } catch {\n    return null\n  }\n}\n\nconst parseSharePayload = (value: string): FavoriteSharePayload => {\n  const parsed = JSON.parse(value) as unknown\n  if (\n    !isRecord(parsed) ||\n    parsed.schemaVersion !== FAVORITE_SHARE_SCHEMA_VERSION ||\n    parsed.format !== 'favorite-share' ||\n    typeof parsed.packageBase64 !== 'string'\n  ) {\n    throw new Error('Invalid favorite share payload')\n  }\n  return parsed as FavoriteSharePayload\n}\n\nexport const readFavoriteSharePackage = (\n  input: ArrayBuffer | Uint8Array | string,\n): Uint8Array => {\n  if (typeof input === 'string') {\n    const parser = new DOMParser()\n    const document = parser.parseFromString(input, 'text/html')\n    const script = document.getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)\n    if (!script?.textContent) {\n      throw new Error('This HTML file does not contain Prompt Optimizer favorite share data')\n    }\n    return base64ToBytes(parseSharePayload(script.textContent).packageBase64)\n  }\n\n  const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)","sourceCodeStart":1422,"sourceCodeEnd":1458,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/utils/favorite-share-export.ts#L1422-L1458","documentation":"Thrown by parseSharePayload when a parsed JSON object does not match the FavoriteSharePayload schema: it must be a record with schemaVersion equal to FAVORITE_SHARE_SCHEMA_VERSION, format equal to 'favorite-share', and a string packageBase64 field. This is a strict schema guard against tampered, outdated, or unrelated JSON.","triggerScenarios":"Importing a share payload whose JSON has a different schemaVersion (old export vs new importer), a missing or misspelled format field, packageBase64 that is null/number/undefined, or JSON that is valid but not a share object at all (e.g. arbitrary JSON embedded in a tEXt chunk with the same keyword).","commonSituations":"Version skew: shares exported by an older app version are imported by a newer one (or vice versa); users hand-editing the embedded JSON; a PNG tEXt keyword collision where unrelated software wrote the same keyword; corrupted base64 that decoded to partial JSON.","solutions":["Confirm FAVORITE_SHARE_SCHEMA_VERSION matches the version written at export time; if not, migrate or re-export","Inspect the embedded JSON (log the tEXt chunk content) to see which field fails: schemaVersion, format, or packageBase64","Validate the payload with parseSharePayload in a try/catch and show a friendly 'unsupported share file version' message","Re-export the share from a current app version instead of editing payloads by hand"],"exampleFix":"// before\nconst pkg = readFavoriteSharePackage(file) // throws on version mismatch\n\n// after\nlet pkg\ntry {\n  pkg = readFavoriteSharePackage(file)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid favorite share payload') {\n    throw new UserError('This share file is unsupported or was exported by an incompatible version.')\n  }\n  throw e\n}","handlingStrategy":"validation","validationCode":"const raw = JSON.parse(text)\nconst ok =\n  raw && typeof raw === 'object' &&\n  raw.schemaVersion === FAVORITE_SHARE_SCHEMA_VERSION &&\n  raw.format === 'favorite-share' &&\n  typeof raw.packageBase64 === 'string'\nif (!ok) throw new UserError('Unsupported share file version')","typeGuard":"const isFavoriteSharePayload = (v: unknown): v is FavoriteSharePayload =>\n  typeof v === 'object' && v !== null &&\n  (v as any).schemaVersion === FAVORITE_SHARE_SCHEMA_VERSION &&\n  (v as any).format === 'favorite-share' &&\n  typeof (v as any).packageBase64 === 'string'","tryCatchPattern":"try { readFavoriteSharePackage(input) } catch (e) { if (e.message === 'Invalid favorite share payload') showVersionMismatchUI(); else throw e }","preventionTips":["Keep exporter and importer schema versions in lockstep; add migration maps","Pre-validate embedded JSON before calling the reader","Show the expected schemaVersion in error UI to speed diagnosis"],"tags":["schema-validation","json","versioning","import"],"backgroundTag":"schema-validation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}