{"record":{"id":"9197361063ba7b03","repo":"linshenkx/prompt-optimizer","slug":"imageimage2imagesession-imagestorageservice-is-u","errorCode":null,"errorMessage":"[ImageImage2ImageSession] ImageStorageService is unavailable; cannot save session","messagePattern":"\\[ImageImage2ImageSession\\] ImageStorageService is unavailable; cannot save session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/stores/session/useImageImage2ImageSession.ts","lineNumber":613,"sourceCode":"          createdAt: Date.now(),\n          accessedAt: Date.now(),\n          source: 'uploaded'\n        },\n        data: b64\n      })\n    }\n\n    return imageId\n  }\n\n  const saveSession = async () => {\n    return await queueImageStorageMaintenance(async () => {\n      const $services = getPiniaServices()\n      if (!$services?.preferenceService) {\n        throw new Error('[ImageImage2ImageSession] PreferenceService is unavailable; cannot save session')\n      }\n      if (!$services?.imageStorageService) {\n        throw new Error('[ImageImage2ImageSession] ImageStorageService is unavailable; cannot save session')\n      }\n\n      // 准备保存的数据\n      let inputImageIdToSave = inputImageId.value\n      // v2: 多列 variants\n      const baseVariantResults: TestVariantResults = {\n        a: testVariantResults.value.a ?? originalImageResult.value,\n        b: testVariantResults.value.b ?? optimizedImageResult.value,\n        c: testVariantResults.value.c,\n        d: testVariantResults.value.d,\n      }\n\n      // 保存输入图像\n      if (inputImageB64.value && !inputImageId.value) {\n        inputImageIdToSave = await saveInputImage(\n          inputImageB64.value,\n          inputImageMime.value,\n          $services.imageStorageService","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/stores/session/useImageImage2ImageSession.ts#L595-L631","documentation":"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.","triggerScenarios":"Calling saveSession when getPiniaServices()?.imageStorageService is falsy, typically while input images or variant results reference assets that must be written via the storage service.","commonSituations":"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.","solutions":["Register the image storage service plugin before session saves can occur","Provide a mock imageStorageService in test setups (must implement save/get used by the session)","If storage is genuinely unavailable in the target environment, avoid attaching images so the save path never needs the service","Check plugin initialization logs/errors at startup to confirm the service constructed successfully"],"exampleFix":"// before\nconst $services = getPiniaServices()\nif (!$services?.imageStorageService) throw new Error('...')\n\n// after (bootstrap)\napp.use(createPinia())\napp.use(piniaPluginServices({ imageStorageService: new IndexedDbImageStorageService() }))","handlingStrategy":"type-guard","validationCode":"const services = getPiniaServices()\nif (!services?.imageStorageService) {\n  // block image-attaching actions or defer save\n}","typeGuard":"const hasImageStorageService = (): boolean =>\n  Boolean(getPiniaServices()?.imageStorageService)","tryCatchPattern":"try {\n  await saveSession()\n} catch (e) {\n  if (e instanceof Error && e.message.includes('ImageStorageService is unavailable')) {\n    // schedule retry after bootstrap\n  } else throw e\n}","preventionTips":["Verify storage plugin installed at startup (assert service non-null)","Mock imageStorageService in unit tests","Confirm IndexedDB/backend availability in target browsers"],"tags":["pinia","dependency-injection","image-storage","session"],"backgroundTag":"missing-service-dependency","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}