jlcodes99/cockpit-tools · warning

[AccountStore] 忽略异常空当前账号,保留本地缓存当前账号: ${target}

Error message

[AccountStore] 忽略异常空当前账号,保留本地缓存当前账号: ${target}

What it means

Defensive console.warn in useAccountStore when resolving the current account for a given target: the resolved account is undefined but the store has a cached currentAccountsByTarget[target] and a non-empty accounts list, and no per-target allowNextEmptyCurrentAccount flag was set. The store keeps the cached current account instead of setting currentAccount to undefined.

Source

Thrown at src/stores/useAccountStore.ts:255

          if (
              fetchCurrentPromises[target] &&
              now - (fetchCurrentLastTimes[target] ?? 0) < DEBOUNCE_MS
          ) {
              return fetchCurrentPromises[target];
          }
          
          fetchCurrentLastTimes[target] = now;
          
          fetchCurrentPromises[target] = (async () => {
              try {
                  const account = await accountService.getCurrentAccount(target);
                  if (
                      !account &&
                      get().currentAccountsByTarget[target] &&
                      get().accounts.length > 0 &&
                      !allowNextEmptyCurrentAccountByTarget[target]
                  ) {
                      console.warn(`[AccountStore] 忽略异常空当前账号,保留本地缓存当前账号: ${target}`);
                      return;
                  }
                  allowNextEmptyCurrentAccountByTarget[target] = false;
                  set((state) => ({
                      currentAccount: account,
                      currentAccountsByTarget: updateCurrentAccountsByTarget(
                          state.currentAccountsByTarget,
                          target,
                          account,
                      ),
                  }));
              } catch (e) {
                  console.error('Failed to fetch current account:', e);
              } finally {
                  allowNextEmptyCurrentAccountByTarget[target] = false;
                  setTimeout(() => {
                      fetchCurrentPromises[target] = undefined;
                  }, 100);

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Usually safe to ignore — cached current account is intentionally retained.
  2. Refetch accounts; if the backend consistently has no current account, fix the backend resolver.
  3. Use the store's explicit switch/logout flow for that target, which sets allowNextEmptyCurrentAccountByTarget first, if clearing is intended.
  4. Clear stale cache via reset if the pointer is confirmed invalid.
  5. Check for API changes in how the current account id is reported per target.
Defensive patterns

Strategy: validation

Validate before calling

const account = resolveCurrentAccount(target);
if (!account && get().currentAccountsByTarget[target] && get().accounts.length > 0 && !allowNextEmptyCurrentAccountByTarget[target]) {
  console.warn(`[AccountStore] ignoring anomalous empty current account: ${target}`);
  return;
}

Type guard

function hasAccountForTarget(v: unknown): v is Account {
  return typeof v === 'object' && v !== null && typeof (v as Account).id === 'string';
}

Prevention

When it happens

Trigger: Current-account resolution returns no match (account id not in list, resolver returned null) while cached value exists, accounts.length > 0, and allowNextEmptyCurrentAccountByTarget[target] is falsy.

Common situations: Backend removed/renamed the current-account id while local cache still references it; partial sync where the accounts list and current pointer disagree; multi-target setups (per-provider targets) where one target's pointer went stale.

Related errors


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