linshenkx/prompt-optimizer · error · Error

error.storage.read

error.storage.read

Error message

[ImageMultiImageSession] Missing input image asset: ${assetId}

What it means

In the image multi-image session store, when a generated image record lacks inline base64 data and an assetId is present, the store fetches the full image from imageStorageService.getImage(assetId). If the returned record is missing or its data is empty/whitespace, createMissingInputAssetError (code error.storage.read) is thrown, flagging a lost input image asset.

Source

Thrown at packages/ui/src/stores/session/useImageMultiImageSession.ts:670

    if (!saved) return

    const parsed =
      typeof saved === 'string'
        ? (JSON.parse(saved) as Record<string, unknown>)
        : (saved as Record<string, unknown>)

    const rawImages = Array.isArray(parsed.inputImages) ? parsed.inputImages : []
    const restoredImages = await Promise.all(
      rawImages.map(async (item) => {
        const record = (item || {}) as Record<string, unknown>
        const assetId = typeof record.assetId === 'string' ? record.assetId : null
        let mimeType = typeof record.mimeType === 'string' ? record.mimeType : 'image/png'
        let b64 = typeof record.b64 === 'string' ? record.b64 : ''

        if (!b64 && assetId) {
          const fullImage = await imageStorageService.getImage(assetId)
          if (!fullImage?.data?.trim()) {
            throw createMissingInputAssetError(assetId)
          }

          b64 = fullImage.data
          mimeType = fullImage.metadata?.mimeType || mimeType
        }

        if (!b64.trim()) {
          throw new Error('[ImageMultiImageSession] Missing input image base64 data in persisted session')
        }

        return {
          id: typeof record.id === 'string' ? record.id : createRuntimeImageId(),
          assetId,
          b64,
          mimeType,
        } satisfies MultiImageSessionInputItem
      }),
    )

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Check whether the asset still exists in image storage for that assetId and inspect how/when it was written (correct DB/store, successful write awaited).
  2. Catch error.storage.read failures per-asset and degrade gracefully (skip/regenerate the image) instead of failing the whole session step.
  3. Persist images with the session record (inline b64) or make eviction of assets also update session records, so references never dangle.

Example fix

// before
const fullImage = await imageStorageService.getImage(assetId)
if (!fullImage?.data?.trim()) {
  throw createMissingInputAssetError(assetId)
}
// after (degrade instead of abort)
const fullImage = await imageStorageService.getImage(assetId).catch(() => undefined)
if (!fullImage?.data?.trim()) {
  console.warn('[ImageMultiImageSession] missing asset, skipping:', assetId)
  return null
}
Defensive patterns

Strategy: fallback

Validate before calling

const exists = await imageStorageService.getImage(assetId).then(r => Boolean(r?.data?.trim())).catch(() => false)
if (!exists) {
  // skip / regenerate the image instead of proceeding
}

Type guard

const hasImageData = (img: Awaited<ReturnType<typeof imageStorageService.getImage>>): img is NonNullable<typeof img> & { data: string } =>
  Boolean(img && img.data && img.data.trim().length > 0)

Try / catch

try { b64 = (await imageStorageService.getImage(assetId))?.data ?? '' } catch (e) {
  if ((e as { code?: string }).code === 'error.storage.read') { /* log & degrade: skip or regenerate */ }
  else throw e
}

Prevention

When it happens

Trigger: A session step references an assetId that was pruned from image storage (cache eviction, storage quota cleanup, IndexedDB corruption), or getImage resolves undefined/empty for that ID — e.g. after clearing browser storage while the session persisted.

Common situations: User clears site data / private-mode storage limits delete the image blob but the session document keeps the assetId; cross-tab writes racing; storage schema migrations that dropped old assets; assets written to a different storage backend than the one read.

Related errors


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