linshenkx/prompt-optimizer · error · Error

[ImageImage2ImageSession] ImageStorageService is unavailable

Error message

[ImageImage2ImageSession] ImageStorageService is unavailable; cannot save session

What it means

saveSession in useImageImage2ImageSession requires ImageStorageService to persist input/variant image assets; if it is absent from the Pinia services container the save aborts with this error. It is checked right after the PreferenceService guard, so it is the second dependency gate on the save path.

Source

Thrown at packages/ui/src/stores/session/useImageImage2ImageSession.ts:613

          createdAt: Date.now(),
          accessedAt: Date.now(),
          source: 'uploaded'
        },
        data: b64
      })
    }

    return imageId
  }

  const saveSession = async () => {
    return await queueImageStorageMaintenance(async () => {
      const $services = getPiniaServices()
      if (!$services?.preferenceService) {
        throw new Error('[ImageImage2ImageSession] PreferenceService is unavailable; cannot save session')
      }
      if (!$services?.imageStorageService) {
        throw new Error('[ImageImage2ImageSession] ImageStorageService is unavailable; cannot save session')
      }

      // 准备保存的数据
      let inputImageIdToSave = inputImageId.value
      // v2: 多列 variants
      const baseVariantResults: TestVariantResults = {
        a: testVariantResults.value.a ?? originalImageResult.value,
        b: testVariantResults.value.b ?? optimizedImageResult.value,
        c: testVariantResults.value.c,
        d: testVariantResults.value.d,
      }

      // 保存输入图像
      if (inputImageB64.value && !inputImageId.value) {
        inputImageIdToSave = await saveInputImage(
          inputImageB64.value,
          inputImageMime.value,
          $services.imageStorageService

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Register the image storage service plugin before session saves can occur
  2. Provide a mock imageStorageService in test setups (must implement save/get used by the session)
  3. If storage is genuinely unavailable in the target environment, avoid attaching images so the save path never needs the service
  4. Check plugin initialization logs/errors at startup to confirm the service constructed successfully

Example fix

// before
const $services = getPiniaServices()
if (!$services?.imageStorageService) throw new Error('...')

// after (bootstrap)
app.use(createPinia())
app.use(piniaPluginServices({ imageStorageService: new IndexedDbImageStorageService() }))
Defensive patterns

Strategy: type-guard

Validate before calling

const services = getPiniaServices()
if (!services?.imageStorageService) {
  // block image-attaching actions or defer save
}

Type guard

const hasImageStorageService = (): boolean =>
  Boolean(getPiniaServices()?.imageStorageService)

Try / catch

try {
  await saveSession()
} catch (e) {
  if (e instanceof Error && e.message.includes('ImageStorageService is unavailable')) {
    // schedule retry after bootstrap
  } else throw e
}

Prevention

When it happens

Trigger: Calling saveSession when getPiniaServices()?.imageStorageService is falsy, typically while input images or variant results reference assets that must be written via the storage service.

Common situations: Missing storage plugin registration during bootstrap; tests with bare Pinia; storage plugin construction failing at startup (e.g. IndexedDB unavailable) and leaving the service undefined; environments without persistent storage.

Related errors


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