{"record":{"id":"097fb7336d47abb9","repo":"jlcodes99/cockpit-tools","slug":"accountstore-target","errorCode":null,"errorMessage":"[AccountStore] 忽略异常空当前账号，保留本地缓存当前账号: ${target}","messagePattern":"\\[AccountStore\\] 忽略异常空当前账号，保留本地缓存当前账号: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/stores/useAccountStore.ts","lineNumber":255,"sourceCode":"          if (\n              fetchCurrentPromises[target] &&\n              now - (fetchCurrentLastTimes[target] ?? 0) < DEBOUNCE_MS\n          ) {\n              return fetchCurrentPromises[target];\n          }\n          \n          fetchCurrentLastTimes[target] = now;\n          \n          fetchCurrentPromises[target] = (async () => {\n              try {\n                  const account = await accountService.getCurrentAccount(target);\n                  if (\n                      !account &&\n                      get().currentAccountsByTarget[target] &&\n                      get().accounts.length > 0 &&\n                      !allowNextEmptyCurrentAccountByTarget[target]\n                  ) {\n                      console.warn(`[AccountStore] 忽略异常空当前账号，保留本地缓存当前账号: ${target}`);\n                      return;\n                  }\n                  allowNextEmptyCurrentAccountByTarget[target] = false;\n                  set((state) => ({\n                      currentAccount: account,\n                      currentAccountsByTarget: updateCurrentAccountsByTarget(\n                          state.currentAccountsByTarget,\n                          target,\n                          account,\n                      ),\n                  }));\n              } catch (e) {\n                  console.error('Failed to fetch current account:', e);\n              } finally {\n                  allowNextEmptyCurrentAccountByTarget[target] = false;\n                  setTimeout(() => {\n                      fetchCurrentPromises[target] = undefined;\n                  }, 100);","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/stores/useAccountStore.ts#L237-L273","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Usually safe to ignore — cached current account is intentionally retained.","Refetch accounts; if the backend consistently has no current account, fix the backend resolver.","Use the store's explicit switch/logout flow for that target, which sets allowNextEmptyCurrentAccountByTarget first, if clearing is intended.","Clear stale cache via reset if the pointer is confirmed invalid.","Check for API changes in how the current account id is reported per target."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const account = resolveCurrentAccount(target);\nif (!account && get().currentAccountsByTarget[target] && get().accounts.length > 0 && !allowNextEmptyCurrentAccountByTarget[target]) {\n  console.warn(`[AccountStore] ignoring anomalous empty current account: ${target}`);\n  return;\n}","typeGuard":"function hasAccountForTarget(v: unknown): v is Account {\n  return typeof v === 'object' && v !== null && typeof (v as Account).id === 'string';\n}","tryCatchPattern":null,"preventionTips":["Set allowNextEmptyCurrentAccountByTarget[target] before deliberate clears (logout/switch).","Validate that the current-account id returned by the backend exists in the accounts list; resync on mismatch.","Clear per-target pointers when the target's accounts list changes to avoid stale cache."],"tags":["state-management","cache","accounts","guard"],"backgroundTag":"empty-current-account-guard","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"}