Foundry376/Mailspring · error

Invalid or expired preview token

Error message

Invalid or expired preview token

What it means

Guard in the quickpreview finishWithData IPC handler: the opaque previewToken submitted by the renderer has no entry in the in-memory previewTokens map — it was never issued, was already consumed (tokens are single-use), or the main process restarted and the map was lost.

Source

Thrown at app/src/browser/quickpreview-ipc.ts:104

  validateSender(event);
  const filepath = getFilePath(event.sender.getURL());
  const md = fs.readFileSync(filepath).toString();
  return require('snarkdown')(md);
};

/**
 * Write preview data using an opaque token instead of a direct path.
 * The token must have been generated by generatePreviewToken().
 */
const finishWithData = (
  event: IpcMainInvokeEvent,
  previewToken: string,
  arrayBuffer: ArrayBuffer
) => {
  validateSender(event);
  const previewPath = previewTokens.get(previewToken);
  if (!previewPath) {
    throw new Error('Invalid or expired preview token');
  }
  // Token is single-use
  previewTokens.delete(previewToken);
  // Still validate the path as defense-in-depth
  const resolvedPath = checkPathIsWithinFiles(previewPath);
  fs.writeFileSync(resolvedPath, Buffer.from(arrayBuffer));
};

/**
 * Capture window screenshot using an opaque token instead of a direct path.
 * The token must have been generated by generatePreviewToken().
 */
const finishCapture = async (event: IpcMainInvokeEvent, previewToken: string) => {
  validateSender(event);
  const previewPath = previewTokens.get(previewToken);
  if (!previewPath) {
    throw new Error('Invalid or expired preview token');
  }

View on GitHub (pinned to 648c685d60)

Solutions

  1. Request a fresh preview token via generatePreviewToken and retry the upload
  2. If it recurs after app restart, ensure the renderer doesn't cache tokens across sessions since the map is process-local
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at app/src/browser/quickpreview-ipc.ts:104 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/a0f9cf3044b80683. Report an issue: GitHub.