linshenkx/prompt-optimizer · error · FavoriteValidationError

Favorite metadata cannot contain inline image data URLs (${p

Error message

Favorite metadata cannot contain inline image data URLs (${path})

What it means

Storage guard (assertFavoriteMetadataHasNoInlineImages) that rejects favorite metadata containing inline image data URLs. It recursively walks the metadata value with cycle tracking (WeakSet) and throws FavoriteValidationError naming the offending path when any string matches INLINE_IMAGE_DATA_URL_RE.

Source

Thrown at packages/core/src/services/favorite/storage-guards.ts:80

    new Set(
      value
        .map((tag) => (typeof tag === 'string' ? tag.trim() : ''))
        .filter(Boolean),
    ),
  )
}

export const getSerializedByteLength = (value: string): number =>
  TEXT_ENCODER.encode(value).byteLength

export const assertFavoriteMetadataHasNoInlineImages = (
  value: unknown,
  path = 'metadata',
  seen: WeakSet<object> = new WeakSet(),
): void => {
  if (typeof value === 'string') {
    if (INLINE_IMAGE_DATA_URL_RE.test(value.trim())) {
      throw new FavoriteValidationError(
        `Favorite metadata cannot contain inline image data URLs (${path})`,
      )
    }
    return
  }

  if (!value || typeof value !== 'object') {
    return
  }

  if (seen.has(value as object)) {
    return
  }
  seen.add(value as object)

  if (Array.isArray(value)) {
    value.forEach((item, index) => {
      assertFavoriteMetadataHasNoInlineImages(item, `${path}[${index}]`, seen)

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Replace inline data URLs in metadata with external URLs or asset IDs
  2. Strip fields matching /^data:image\// before saving
  3. Store large binaries in dedicated blob storage and keep only references in favorite metadata

Example fix

// before
favorite.metadata = { preview: `data:image/png;base64,${b64}` };

// after
favorite.metadata = { previewUrl: await uploadAndGetUrl(b64) };
Defensive patterns

Strategy: validation

Validate before calling

const INLINE_IMAGE_RE = /^data:image\/[a-z+.-]+;base64,/i;
const metadataHasInlineImage = (m: unknown): boolean => {
  if (typeof m === 'string') return INLINE_IMAGE_RE.test(m.trim());
  if (m && typeof m === 'object') return Object.values(m).some(metadataHasInlineImage);
  return false;
};
if (metadataHasInlineImage(favorite.metadata)) delete favorite.metadata.preview;

Type guard

const isSafeMetadata = (m: unknown): boolean => !metadataHasInlineImage(m);

Try / catch

try {
  await manager.addFavorite(fav);
} catch (e) {
  if (e instanceof FavoriteValidationError && /inline image/.test(e.message)) {
    // message names the offending path; remove that field and retry
  }
}

Prevention

When it happens

Trigger: Saving or normalizing a favorite whose metadata contains a string matching an inline image data URL (data:image/...;base64,...) at any nesting depth — e.g. metadata.thumbnail or a deeply nested preview field.

Common situations: Attaching generated-image previews or avatars as base64 strings in metadata instead of URLs/asset IDs; metadata copied from APIs that inline base64 images.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/5cc881208ffac7ce. Report an issue: GitHub.