linshenkx/prompt-optimizer · error · Error
Invalid favorite share payload
Error message
Invalid favorite share payload
What it means
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.
Source
Thrown at packages/ui/src/utils/favorite-share-export.ts:1440
const textBytes = data.slice(offset)
try {
return compressionFlag === 1
? strFromU8(unzlibSync(textBytes))
: strFromU8(textBytes)
} catch {
return null
}
}
const parseSharePayload = (value: string): FavoriteSharePayload => {
const parsed = JSON.parse(value) as unknown
if (
!isRecord(parsed) ||
parsed.schemaVersion !== FAVORITE_SHARE_SCHEMA_VERSION ||
parsed.format !== 'favorite-share' ||
typeof parsed.packageBase64 !== 'string'
) {
throw new Error('Invalid favorite share payload')
}
return parsed as FavoriteSharePayload
}
export const readFavoriteSharePackage = (
input: ArrayBuffer | Uint8Array | string,
): Uint8Array => {
if (typeof input === 'string') {
const parser = new DOMParser()
const document = parser.parseFromString(input, 'text/html')
const script = document.getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)
if (!script?.textContent) {
throw new Error('This HTML file does not contain Prompt Optimizer favorite share data')
}
return base64ToBytes(parseSharePayload(script.textContent).packageBase64)
}
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)View on GitHub (pinned to 3e677b1d9f)
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
Example fix
// before
const pkg = readFavoriteSharePackage(file) // throws on version mismatch
// after
let pkg
try {
pkg = readFavoriteSharePackage(file)
} catch (e) {
if (e instanceof Error && e.message === 'Invalid favorite share payload') {
throw new UserError('This share file is unsupported or was exported by an incompatible version.')
}
throw e
} Defensive patterns
Strategy: validation
Validate before calling
const raw = JSON.parse(text)
const ok =
raw && typeof raw === 'object' &&
raw.schemaVersion === FAVORITE_SHARE_SCHEMA_VERSION &&
raw.format === 'favorite-share' &&
typeof raw.packageBase64 === 'string'
if (!ok) throw new UserError('Unsupported share file version') Type guard
const isFavoriteSharePayload = (v: unknown): v is FavoriteSharePayload => typeof v === 'object' && v !== null && (v as any).schemaVersion === FAVORITE_SHARE_SCHEMA_VERSION && (v as any).format === 'favorite-share' && typeof (v as any).packageBase64 === 'string'
Try / catch
try { readFavoriteSharePackage(input) } catch (e) { if (e.message === 'Invalid favorite share payload') showVersionMismatchUI(); else throw e } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Unsupported Garden response schema
- Invalid import data format
- variables[${index}] is missing a valid "position" object.
- variables[${index}].position is missing a valid "originalTex
- variables[${index}] is missing a valid "reason" field.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/fc83740cd0af85f2.
Report an issue: GitHub.