{"record":{"id":"7e86ab2066fdf353","repo":"vuejs/devtools-v6","slug":"storage-wasn-t-initialized-with-init","errorCode":null,"errorMessage":"Storage wasn't initialized with 'init()'","messagePattern":"Storage wasn't initialized with 'init\\(\\)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared-utils/src/storage.ts","lineNumber":82,"sourceCode":"}\n\nexport function clearStorage() {\n  checkStorage()\n  if (useStorage) {\n    storageData = {}\n    target.chrome.storage.local.clear()\n  }\n  else {\n    try {\n      localStorage.clear()\n    }\n    catch (e) {}\n  }\n}\n\nfunction checkStorage() {\n  if (!storageData) {\n    throw new Error('Storage wasn\\'t initialized with \\'init()\\'')\n  }\n}\n\nfunction getDefaultValue(value, defaultValue) {\n  if (value == null) {\n    return defaultValue\n  }\n  return value\n}\n","sourceCodeStart":64,"sourceCodeEnd":92,"githubUrl":"https://github.com/vuejs/devtools-v6/blob/dd2ab5d4275187cbd81952a2a3d53c335643c1f4/packages/shared-utils/src/storage.ts#L64-L92","documentation":"The shared storage utility wraps localStorage (or an in-memory fallback) and only loads data into `storageData` during init(). checkStorage() throws this when get/set/remove/clear is called before init(), because there is nowhere to read or write values. It is a lifecycle guard, not a data error.","triggerScenarios":"Calling getStorage, setStorage, removeStorage, or clearStorage before `await init()` (or when init() failed silently — its load errors are swallowed in a try/catch, leaving storageData undefined).","commonSituations":"Module-level code that reads a stored setting at import time before init() runs; forgetting to await the async init(); init() failing because localStorage is disabled (private mode, SSR without a shim) and the failure being caught and ignored.","solutions":["Call and await `init()` from shared-utils storage before any other storage call, ideally at application startup.","Ensure init() actually succeeds: in browsers with localStorage blocked (private browsing) provide a storage shim or in-memory fallback.","Move storage reads/writes out of module top-level code into a post-init lifecycle hook.","Wrap storage access in a helper that lazily calls init() if storageData is not yet loaded."],"exampleFix":"// before\nimport { getStorage } from '@vue-devtools/shared-utils'\nconst lastApp = getStorage('last-open-app') // throws\n\n// after\nimport { init, getStorage } from '@vue-devtools/shared-utils'\nawait init()\nconst lastApp = getStorage('last-open-app')","handlingStrategy":"try-catch","validationCode":"import { init } from '@vue-devtools/shared-utils'\nawait init() // before ANY get/set/remove/clearStorage call","typeGuard":"function storageReady() { return !!storageData } // or expose/init-check equivalent","tryCatchPattern":"try {\n  setStorage('key', value)\n} catch (e) {\n  if (String(e).includes(\"init()\")) { await init(); setStorage('key', value) }\n  else throw e\n}","preventionTips":["Await init() as the first step of app startup","Never call storage helpers from module top-level code","Provide an in-memory shim when localStorage is unavailable (private mode/SSR)","Note init() swallows load errors — verify it succeeded before use"],"tags":["storage","initialization-order","lifecycle","localstorage"],"backgroundTag":"storage-not-initialized","analyzedSha":"dd2ab5d4275187cbd81952a2a3d53c335643c1f4","analyzedAt":"2026-08-31T12:41:59.822Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}