jlcodes99/cockpit-tools · warning

[AccountStore] 清理超限缓存失败:

Error message

[AccountStore] 清理超限缓存失败:

What it means

scheduleAccountStoreQuotaRecovery defers a setTimeout(0) cleanup that removes the account store cache key and two legacy keys to recover from a QuotaExceededError during a persist write. If even the removals fail, the error is warned and the schedule flag is reset in finally.

Source

Thrown at src/stores/useAccountStore.ts:40

      error.name === 'QuotaExceededError' ||
      error.code === 22 ||
      error.code === 1014
    );
  }
  const message = String(error);
  return message.includes('QuotaExceededError') || message.includes('quota');
}

function scheduleAccountStoreQuotaRecovery(storageKey: string) {
  if (typeof window === 'undefined' || accountStoreQuotaCleanupScheduled) return;
  accountStoreQuotaCleanupScheduled = true;
  setTimeout(() => {
    try {
      localStorage.removeItem(storageKey);
      localStorage.removeItem(LEGACY_ACCOUNTS_CACHE_KEY);
      localStorage.removeItem(LEGACY_CURRENT_ACCOUNT_CACHE_KEY);
    } catch (error) {
      console.warn('[AccountStore] 清理超限缓存失败:', error);
    } finally {
      accountStoreQuotaCleanupScheduled = false;
    }
  }, 0);
}

const accountStoreStorage = createJSONStorage(() => ({
  getItem: (name: string) => {
    try {
      return localStorage.getItem(name);
    } catch (error) {
      console.warn(`[AccountStore] 读取持久化数据失败: ${name}`, error);
      return null;
    }
  },
  setItem: (name: string, value: string) => {
    try {
      localStorage.setItem(name, value);

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Verify storage availability once at startup and disable persistence when unavailable
  2. Clear site data manually to reset the quota
  3. Keep the finally-based flag reset so recovery can be rescheduled later
  4. Reduce persisted state size (partialize the zustand store) to avoid quota pressure

Example fix

// before
} catch (error) {
  console.warn('[AccountStore] 清理超限缓存失败:', error);
}
// after
} catch (error) {
  console.warn('[AccountStore] 清理超限缓存失败:', error);
  console.warn('[AccountStore] 请手动清除站点数据以恢复账号缓存');
}
Defensive patterns

Strategy: try-catch

Validate before calling

function storageWritable(): boolean {
  try { localStorage.setItem('__probe__', '1'); localStorage.removeItem('__probe__'); return true; }
  catch { return false; }
}

Try / catch

try {
  localStorage.removeItem(storageKey);
  localStorage.removeItem(LEGACY_ACCOUNTS_CACHE_KEY);
  localStorage.removeItem(LEGACY_CURRENT_ACCOUNT_CACHE_KEY);
} catch (error) {
  console.warn('[AccountStore] 清理超限缓存失败:', error);
} finally {
  accountStoreQuotaCleanupScheduled = false;
}

Prevention

When it happens

Trigger: localStorage.removeItem throws during quota recovery — storage disabled, page in a blocked-storage context, or the environment throwing on any storage access after a quota violation.

Common situations: Safari private mode where all storage APIs throw; embedded webviews with storage partitioned off; persistent quota pressure from other large keys.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/5c048e5b97cfa996. Report an issue: GitHub.