Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Don't fail YNAB exporter on unmapped accounts #644

Open
whatuserever opened this issue Feb 9, 2025 · 0 comments · May be fixed by #646
Open

Feature Request: Don't fail YNAB exporter on unmapped accounts #644

whatuserever opened this issue Feb 9, 2025 · 0 comments · May be fixed by #646
Labels
enhancement New feature or request

Comments

@whatuserever
Copy link
Contributor

whatuserever commented Feb 9, 2025

Is your feature request related to a problem? Please describe.
I want to use Caspion to export transactions into YNAB, but I have multiple accounts on the same financial providers and I don't want to export all of them.
This is impossible at the moment. If your YNAB config has unmapped accounts, the YNAB exporter hangs and logs the following:

Unhandled account number <accountNumber>

Describe the solution you'd like
Simply ignore transactions from accounts that have no YNAB mapping. Emit a message in the logger indicating which accounts were skipped.

Describe alternatives you've considered
I see 2 options:

  1. Always ignore unmapped accounts
  2. Add an option in the config to allow ignoring unmapped accounts. If it's enabled - skip. Otherwise - error.

Additional context
The root cause is the throw statement here:

function getYnabAccountIdByAccountNumberFromTransaction(transactionAccountNumber: string): string {
const ynabAccountId = ynabConfig!.options.accountNumbersToYnabAccountIds[transactionAccountNumber];
if (!ynabAccountId) {
throw new Error(`Unhandled account number ${transactionAccountNumber}`);
}
return ynabAccountId;
}

I think the proper solution would be to refactor the YNAB exporter such that it exports transactions by account. This way the skip can be done before processing the transactions, and we'll have a single log line per skipped account instead of a line per transaction from skipped accounts.

Something along the lines of:

const createTransactions: ExportTransactionsFunction = async ({ transactionsToCreate, startDate }, eventPublisher) => {
  // ...
  const transactionsByAccount = // mapping from accountNumber to list of transactions from that account
  const results = transactionsByAccount.forEach(createTransactionsByAccount(accountNumber, accountTransactions))
  return sum(results)
}

function createTransactionsByAccount(accountNumber, accountTransactions) {
  if (unmapped(accountNumber)) {
    emit("skipping message") // or throw, depending on the decided approach
    return
  }
  // process transactions as before
}

I'm willing to work on this, but let me know what you think first :)

@whatuserever whatuserever added the enhancement New feature or request label Feb 9, 2025
@whatuserever whatuserever linked a pull request Feb 10, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant