actualbudget/actual · error

Internal error: account with ID ${targetAccountId} not found

Error message

Internal error: account with ID ${targetAccountId} not found.

What it means

AccountsPage's mobile drag-and-drop account reordering throws this when a drop target ('after' position) account ID cannot be found in the local `accounts` array. It signals a state desync between the drag payload and the rendered account list. Note the throw interpolates `targetAccountId`, which is not the variable computed in this region (`targetAccountIndex`), so the message may print `undefined` — itself a bug worth fixing while handling the error.

Source

Thrown at packages/desktop-client/src/components/mobile/accounts/AccountsPage.tsx:492

          />
        );
      },
      onReorder: e => {
        const [key] = e.keys;
        const accountIdToMove = key as AccountEntity['id'];
        const targetAccountId = e.target.key as AccountEntity['id'];

        if (e.target.dropPosition === 'before') {
          moveAccount.mutate({
            id: accountIdToMove,
            targetId: targetAccountId,
          });
        } else if (e.target.dropPosition === 'after') {
          const targetAccountIndex = accounts.findIndex(
            account => account.id === e.target.key,
          );
          if (targetAccountIndex === -1) {
            throw new Error(
              `Internal error: account with ID ${targetAccountId} not found.`,
            );
          }

          const nextToTargetAccount = accounts[targetAccountIndex + 1];

          moveAccount.mutate({
            id: accountIdToMove,
            // Due to the way `moveAccount` works, we use the account next to the
            // actual target account here because `moveAccount` always shoves the
            // account *before* the target account.
            // On the other hand, using `null` as `targetId`moves the account
            // to the end of the list.
            targetId: nextToTargetAccount?.id || null,
          });
        }
      },
    });

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Refresh the accounts list (reload from the store/server) and retry the drag operation.
  2. Fix the throw to interpolate the actual target key (`e.target.key`) instead of the undefined `targetAccountId` so the message is debuggable.
  3. Gracefully return instead of throwing when the index is -1, since a stale drop target is a UI-level condition, not a fatal internal error.
  4. Check for concurrent account deletion (sync removing the target account) in your app state.

Example fix

// before
throw new Error(
  `Internal error: account with ID ${targetAccountId} not found.`,
);
// after
const targetAccountId = e.target.key;
if (targetAccountIndex === -1) {
  throw new Error(
    `Internal error: account with ID ${targetAccountId} not found.`,
  );
}
Defensive patterns

Strategy: validation

Validate before calling

const targetAccountIndex = accounts.findIndex(a => a.id === e.target.key);
if (e.target.dropPosition === 'after' && targetAccountIndex === -1) {
  return; // stale drop target; skip instead of throwing
}

Type guard

function accountExists(accounts: { id: string }[], id: string): boolean {
  return accounts.some(a => a.id === id);
}

Try / catch

try {
  await onReorder(e);
} catch (err) {
  if (String(err).includes('not found')) {
    await refreshAccounts(); // resync and recover
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Drag-reordering an account with dropPosition === 'after' where `accounts.findIndex(account => account.id === e.target.key)` returns -1: the drop target key is stale or not present in the accounts list at the moment the reorder event fires.

Common situations: Stale accounts state during a concurrent sync (account deleted on another device mid-drag), a dropped item whose target key belongs to a different list section, or a component re-render that replaced `accounts` between drag start and drop.

Related errors


AI-assisted analysis of actualbudget/actual@d4334cb6e6 (2026-08-29). Data as JSON: /api/errors/6c3959ea343c0b02. Report an issue: GitHub.