{"record":{"id":"aa1b9959cabaa998","repo":"jlcodes99/cockpit-tools","slug":"accountstore-name-aa1b99","errorCode":null,"errorMessage":"[AccountStore] 写入持久化数据失败: ${name}","messagePattern":"\\[AccountStore\\] 写入持久化数据失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/stores/useAccountStore.ts","lineNumber":71,"sourceCode":"      return null;\n    }\n  },\n  setItem: (name: string, value: string) => {\n    try {\n      localStorage.setItem(name, value);\n    } catch (error) {\n      if (isQuotaExceededError(error)) {\n        if (!accountStoreQuotaWarned) {\n          console.warn(\n            '[AccountStore] 本地缓存空间不足，已自动清理账号缓存并回退为仅内存态。',\n            error\n          );\n          accountStoreQuotaWarned = true;\n        }\n        scheduleAccountStoreQuotaRecovery(name);\n        return;\n      }\n      console.warn(`[AccountStore] 写入持久化数据失败: ${name}`, error);\n    }\n  },\n  removeItem: (name: string) => {\n    try {\n      localStorage.removeItem(name);\n    } catch (error) {\n      console.warn(`[AccountStore] 删除持久化数据失败: ${name}`, error);\n    }\n  },\n}));\n\nfunction toPersistedTokenSnapshot(token: TokenData): TokenData {\n  return {\n    access_token: '',\n    refresh_token: '',\n    expires_in: 0,\n    expiry_timestamp: 0,\n    token_type: token.token_type || 'Bearer',","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/stores/useAccountStore.ts#L53-L89","documentation":"The persist storage's setItem catches write failures. For QuotaExceededError specifically it schedules quota recovery (deletes caches) and optionally warns once; any other write error is warned with the key name. The store keeps running in memory even though nothing was persisted.","triggerScenarios":"localStorage.setItem throws when persisting account state: quota exceeded by large account lists, storage disabled/private mode, or any storage exception from an embedded webview.","commonSituations":"Many large accounts inflating persisted JSON past quota; private browsing; storage blocked by browser policy after repeated quota violations.","solutions":["Reduce persisted payload via the persist option partialize (store only needed fields)","Let scheduleAccountStoreQuotaRecovery clear caches, then retry the write","Check localStorage availability at startup and degrade gracefully","Inspect the logged error name: QuotaExceededError vs SecurityError have different fixes"],"exampleFix":"// before\nconsole.warn(`[AccountStore] 写入持久化数据失败: ${name}`, error);\n// after\nconsole.warn(`[AccountStore] 写入持久化数据失败: ${name}`, error);\nif (error instanceof DOMException && error.name === 'QuotaExceededError') {\n  scheduleAccountStoreQuotaRecovery(name);\n}","handlingStrategy":"validation","validationCode":"function estimatePersistSize(state: unknown): boolean {\n  return JSON.stringify(state).length < 4_500_000; // stay under ~5MB quota\n}","typeGuard":"function isQuotaError(error: unknown): error is DOMException {\n  return error instanceof DOMException &&\n    (error.name === 'QuotaExceededError' || error.name === 'NS_ERROR_DOM_QUOTA_REACHED');\n}","tryCatchPattern":"setItem: (name: string, value: string) => {\n  try { localStorage.setItem(name, value); }\n  catch (error) {\n    if (isQuotaError(error)) { scheduleAccountStoreQuotaRecovery(name); return; }\n    console.warn(`[AccountStore] 写入持久化数据失败: ${name}`, error);\n  }\n}","preventionTips":["Use persist partialize to persist only essential account fields","Branch on QuotaExceededError vs other errors for the right recovery","Schedule quota cleanup and retry the write once after eviction","Monitor persisted payload size as account count grows"],"tags":["localstorage","quota","zustand-persist"],"backgroundTag":"localstorage-quota-exceeded","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}