{"record":{"id":"c837377e3bf9633e","repo":"linshenkx/prompt-optimizer","slug":"basicsystemsession-imagestorageservice-is-unavai-c83737","errorCode":null,"errorMessage":"[BasicSystemSession] ImageStorageService is unavailable; cannot restore test image","messagePattern":"\\[BasicSystemSession\\] ImageStorageService is unavailable; cannot restore test image","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/stores/session/useBasicSystemSession.ts","lineNumber":607,"sourceCode":"      if (saved) {\n        const parsed =\n          typeof saved === 'string'\n            ? (JSON.parse(saved) as BasicSystemSessionState)\n            : (saved as BasicSystemSessionState)\n\n        const savedTestImageAssetId = typeof parsed.testImageAssetId === 'string' && parsed.testImageAssetId.trim()\n          ? parsed.testImageAssetId.trim()\n          : null\n        let restoredTestImageAssetId = savedTestImageAssetId\n        let restoredTestImageB64: string | null = null\n        let restoredTestImageMimeType = typeof parsed.testImageMimeType === 'string'\n          ? parsed.testImageMimeType\n          : ''\n\n        if (savedTestImageAssetId) {\n          try {\n            if (!$services.imageStorageService) {\n              throw new Error(\n                '[BasicSystemSession] ImageStorageService is unavailable; cannot restore test image',\n              )\n            }\n\n            const storedImage = await $services.imageStorageService.getImage(savedTestImageAssetId)\n            if (!storedImage?.data?.trim()) {\n              console.info('[BasicSystemSession] Test image asset is missing; restoring session without it')\n              restoredTestImageAssetId = null\n              restoredTestImageMimeType = ''\n              shouldRepairMissingTestImage = true\n            } else {\n              restoredTestImageB64 = storedImage.data\n              restoredTestImageMimeType = storedImage.metadata?.mimeType || restoredTestImageMimeType || 'image/png'\n            }\n          } catch (error) {\n            console.warn(\n              '[BasicSystemSession] Failed to restore test image; restoring text session without it:',\n              error,","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/stores/session/useBasicSystemSession.ts#L589-L625","documentation":"During restoreSession, if the saved session references a stored test image asset but ImageStorageService is unavailable, the store throws before it can call getImage. Restoration of the image is mandatory when an asset id exists, so a missing service aborts that part of the restore.","triggerScenarios":"restoreSession when parsed.testImageAssetId is truthy and getPiniaServices().imageStorageService is falsy. The throw happens inside a try block, so it is likely converted to a handled restore failure downstream.","commonSituations":"Tests or SSR rendering that mount the session store without service plugins; async boot where restore runs before service installation; environments (private mode) where the storage plugin failed to construct.","solutions":["Ensure service plugins are installed on Pinia before restoreSession is dispatched (await app bootstrap)","Register a mock imageStorageService in test setups that restore sessions","If the service is optional in your deployment, catch the error and restore the session without the image, prompting re-upload"],"exampleFix":"// before\nawait session.restoreSession() // throws if asset id saved but no service\n\n// after\nconst services = getPiniaServices()\nif (services?.imageStorageService) {\n  await session.restoreSession()\n} else {\n  await session.restoreSession().catch(e => console.warn('image not restored:', e.message))\n}","handlingStrategy":"fallback","validationCode":"const services = getPiniaServices()\nif (services?.imageStorageService) {\n  await session.restoreSession()\n} else {\n  await session.restoreSession().catch(() => {}) // degrade gracefully\n}","typeGuard":"const canRestoreImages = (): boolean =>\n  Boolean(getPiniaServices()?.imageStorageService)","tryCatchPattern":"try {\n  await session.restoreSession()\n} catch (e) {\n  if (e instanceof Error && e.message.includes('cannot restore test image')) {\n    // continue with image-less session\n  } else throw e\n}","preventionTips":["Await service plugin installation before triggering restore","Provide storage mocks in test environments"],"tags":["pinia","session-restore","image-storage"],"backgroundTag":"missing-service-dependency","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}