Skip to content

fix(connectors): EN-1095 skip unsupported-currency rows + big.Int amount conversion (M-CON1, M-CON5) - #781

Merged
fguery merged 3 commits into
mainfrom
fix/EN-1095_connector_currency_skip
Jun 30, 2026
Merged

fguery merged 3 commits into
mainfrom
fix/EN-1095_connector_currency_skip

Conversation

@fguery

@fguery fguery commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of 2 for EN-1095 (currency-error handling). Pagination/watermark fixes (M-CON2/M-CON3) follow in a separate PR.

M-CON1 — unsupported currency froze the fetch pipeline

Unsupported-currency rows returned a retryable error from the fetch path. With no MaximumAttempts, FetchNext* retried the same row forever — ingestion frozen for the account while hammering the PSP.

Fix: adopt the wise/atlar pattern — translate wraps plugins.ErrCurrencyNotSupported, the fetch loop detects it via errors.Is, logs, and skips the row so other currencies keep flowing.

  • stripe/payments.go, moneycorp/payments.go + balances.go, plaid (client/amount_utils.go + payments.go + balances.go)
  • wise/balances.go — the audit missed this; wise/payments was already correct but balances bare-errored
  • Out of scope (verified): moneycorp/transfers.go + payouts.go are outbound create ops where failing on unsupported currency is correct; EE connectors are clean (cursor/since_id, not currency-gated)

M-CON5 — increase converted money through float64

mapPayment used big.NewInt(int64(math.Abs(float64(transaction.Amount)))), round-tripping an int64 through float64 (loses precision above 2^53, overflows on MinInt64). Now new(big.Int).Abs(big.NewInt(transaction.Amount)) — exact across the full int64 range.

Tests

TDD: existing "fails on unsupported currency" specs flipped to assert skip; new skip specs for balances; new precision spec for increase (2^53+1). All affected packages green; go build ./... + go vet clean.

fabrice guery added 2 commits June 26, 2026 15:08
…s (M-CON1)

Unsupported-currency transactions/balances returned a retryable error from
the fetch path. With no MaximumAttempts, FetchNext* retried the same row
forever, freezing ingestion for the whole account while hammering the PSP.

Adopt the wise/atlar pattern: translate wraps plugins.ErrCurrencyNotSupported
and the fetch loop detects it via errors.Is, logs, and skips the row so
ingestion continues for supported currencies.

- stripe/payments.go: ErrUnsupportedCurrency now wraps the sentinel; loop skips
- moneycorp/payments.go + balances.go: wrap currency.ErrMissingCurrencies, skip
- plaid/client/amount_utils.go: wrap; plaid payments (Added/Modified) + balances skip
- wise/balances.go: skip the single unsupported balance instead of erroring
  (audit missed this; wise/payments was already correct)

Audit cited stripe/moneycorp/plaid; the cross-connector sweep also found
wise/balances and confirmed moneycorp/transfers+payouts are create ops where
failing on unsupported currency is correct (left unchanged).

Constraint: Skipping (not just non-retryable) is required to keep ingesting other rows
Rejected: Make the error non-retryable only | still drops the whole batch, ingestion stalls
Confidence: high
Scope-risk: moderate
Directive: Currency skip applies to FETCH/ingestion loops only — outbound create ops must still fail on unsupported currency
Not-tested: Real PSP behaviour when an account's own balance currency is unsupported
…64 (M-CON5)

mapPayment computed the absolute amount as
big.NewInt(int64(math.Abs(float64(transaction.Amount)))), round-tripping an
int64 through float64. That loses precision above 2^53 minor units and
overflows on MinInt64 (whose absolute value is not representable as int64).

Use new(big.Int).Abs(big.NewInt(transaction.Amount)) — exact across the full
int64 range and kept entirely in the integer domain. Drop the now-unused math
import.

Confidence: high
Scope-risk: narrow
Not-tested: amounts at exactly math.MinInt64 (test uses 2^53+1 to prove precision)
@fguery
fguery requested a review from a team as a code owner June 26, 2026 14:12
@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fadb0dee-ce15-4d42-aed1-10aedf26f7e4

📥 Commits

Reviewing files that changed from the base of the PR and between 577661d and a8aa6fc.

📒 Files selected for processing (2)
  • internal/connectors/plugins/public/moneycorp/payments_test.go
  • internal/connectors/plugins/public/moneycorp/transfers.go

Walkthrough

The PR updates Increase payment amount mapping to use integer absolute values and changes Moneycorp, Plaid, Stripe, and Wise connectors to skip balances or payments with unsupported currencies instead of failing. Tests were added or updated for each affected path.

Changes

Increase amount precision

Layer / File(s) Summary
Amount precision
internal/connectors/plugins/public/increase/payments.go, internal/connectors/plugins/public/increase/payments_test.go
mapPayment switches to integer absolute-value math for Amount, and the new tests check exact results for large positive and negative inputs.

Unsupported currency handling

Layer / File(s) Summary
Moneycorp balances
internal/connectors/plugins/public/moneycorp/balances.go, internal/connectors/plugins/public/moneycorp/balances_test.go
fetchNextBalances skips balances when precision lookup reports missing currencies, and the tests assert unsupported entries are omitted.
Moneycorp payments
internal/connectors/plugins/public/moneycorp/payments.go, internal/connectors/plugins/public/moneycorp/transfers.go, internal/connectors/plugins/public/moneycorp/payments_test.go
Missing-currency precision errors are translated to plugins.ErrCurrencyNotSupported, the fetch loop skips matching transactions, transfer conversion returns the wrapped error, and the tests assert unsupported payments are omitted.
Plaid balances
internal/connectors/plugins/public/plaid/client/amount_utils.go, internal/connectors/plugins/public/plaid/balances.go, internal/connectors/plugins/public/plaid/balances_test.go
Unsupported currencies are mapped to plugins.ErrCurrencyNotSupported, balance fetches log and return an empty response for them, and tests cover the skipped-balance path.
Plaid payments
internal/connectors/plugins/public/plaid/payments.go, internal/connectors/plugins/public/plaid/payments_test.go
Added and modified transactions with unsupported currencies are logged and skipped, and the tests assert no payments are returned.
Stripe payments
internal/connectors/plugins/public/stripe/payments.go, internal/connectors/plugins/public/stripe/payments_test.go
ErrUnsupportedCurrency now wraps plugins.ErrCurrencyNotSupported, fetches skip matching translation errors, and the test expects an empty page with HasMore true.
Wise balances
internal/connectors/plugins/public/wise/balances.go, internal/connectors/plugins/public/wise/balances_test.go
Unsupported balance currencies are logged and skipped, and the tests assert an empty result with HasMore false.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • laouji

Poem

I hopped through ledgers, ears held high,
and nibbled errors as they went by.
Big integers kept the totals true,
while skipped-up coins just waved “boo-hoo!”
Thump thump—each payment found its hue. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main changes: unsupported-currency skipping and big.Int amount conversion.
Description check ✅ Passed The description is directly related to the connector currency-error handling and amount conversion updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/EN-1095_connector_currency_skip

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NumaryBot

NumaryBot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

🛑 Changes requested — automated review

The PR successfully introduces skip logic for unsupported-currency rows across Moneycorp, Plaid, Stripe, and Wise connectors, and correctly switches Increase to integer absolute-value amount conversion. However, two major gaps remain in the Moneycorp implementation. First, the Transfer transaction code path returns the raw currency.ErrMissingCurrencies error rather than wrapping it into plugins.ErrCurrencyNotSupported, so the new skip branch never triggers for Transfer-type transactions with unsupported currencies — those still cause fetch failures and infinite retries. Second, when every newly fetched row is skipped due to an unsupported currency, the pagination watermark is never advanced (it relies on the last element of the returned payments slice), causing the same unsupported rows to be re-fetched on every subsequent poll. Both issues must be resolved before the skip logic can be considered complete and production-safe.

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumaryBot posted 1 new inline finding.

Summary: #781 (comment)


payment, err := p.transactionToPayment(ctx, transaction)
if err != nil {
if errors.Is(err, plugins.ErrCurrencyNotSupported) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 [major] Wrap unsupported currencies from Moneycorp transfer payments

When a Moneycorp transaction is a debit Transfer, transactionToPayment returns through fetchAndTranslateTransfer, whose transferToPayment still returns the bare currency.ErrMissingCurrencies for an unsupported TransferCurrency. This new skip branch only catches plugins.ErrCurrencyNotSupported, so those transfer rows still fail FetchNextPayments and keep retrying instead of being skipped.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
internal/connectors/plugins/public/increase/payments_test.go (1)

640-673: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a MinInt64 regression case.

These tests lock in the 2^53+1 precision fix, but the other edge called out here is MinInt64, which is the boundary that breaks integer negation. Adding an explicit const amount int64 = -1 << 63 case would cover that exact failure mode too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/connectors/plugins/public/increase/payments_test.go` around lines
640 - 673, Add an explicit MinInt64 regression test in the same mapPayment
coverage alongside the existing large positive and negative amount cases. The
current tests in mapPayment only verify the 2^53+1 precision fix; add a case
using the exact MinInt64 boundary and assert the resulting payment amount is
preserved correctly without overflow when taking the absolute value. Use the
existing plg.mapPayment and payment.Amount assertions to cover this edge case.
internal/connectors/plugins/public/stripe/payments_test.go (1)

233-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that the skip path still advances NewState.

This test covers the empty-page behavior, but it doesn't verify the part that prevents the retry loop: pagination state must still move forward after skipping the unsupported row. Returning a non-empty client.Timeline here and asserting it is serialized into res.NewState would lock in that contract.

Suggested test tweak
 			m.EXPECT().GetPayments(gomock.Any(), accRef, gomock.Any(), int64(pageSize)).Return(
 				p,
-				client.Timeline{},
+				client.Timeline{LatestID: "someid"},
 				true,
 				nil,
 			)
 			res, err := plg.FetchNextPayments(ctx, req)
 			Expect(err).To(BeNil())
 			Expect(res.Payments).To(BeEmpty())
 			Expect(res.HasMore).To(BeTrue())
+
+			var state paymentsState
+			err = json.Unmarshal(res.NewState, &state)
+			Expect(err).To(BeNil())
+			Expect(state.Timeline.LatestID).To(Equal("someid"))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/connectors/plugins/public/stripe/payments_test.go` around lines 233
- 242, The empty-page test for FetchNextPayments only checks Payments and
HasMore, but it does not verify that the pagination state advances after
skipping the unsupported row. Update the test around plg.FetchNextPayments to
return a non-empty client.Timeline from the mocked GetPayments call and assert
that the resulting res.NewState contains the serialized timeline state, so the
skip path in FetchNextPayments and its NewState handling are covered.
internal/connectors/plugins/public/plaid/payments_test.go (1)

86-127: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the ingestion-progress contract on the skipped-payment path.

This only proves the Added branch is non-fatal. It doesn't verify that the cursor still advances (NewState/HasMore) after skipping, and it leaves the separate resp.Modified skip branch in internal/connectors/plugins/public/plaid/payments.go unexercised. A regression in either path would still pass here. Based on PR objectives, the skipped-row path must keep ingestion moving.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/connectors/plugins/public/plaid/payments_test.go` around lines 86 -
127, The skipped-payment test in FetchNextPayments only asserts empty payments
and misses the ingestion-progress contract. Update the plaid payments test
around plg.FetchNextPayments to also verify cursor/state advancement (NewState
and HasMore) after skipping unsupported currencies, using the same
ListTransactions mock/NextCursor path. Add coverage for the resp.Modified skip
branch in internal/connectors/plugins/public/plaid/payments.go so both
skipped-row paths still advance ingestion correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/connectors/plugins/public/moneycorp/payments.go`:
- Around line 101-108: The transfer flow in `fetchAndTranslateTransfer` is
returning the raw missing-currency error instead of normalizing it, so
unsupported transfer transactions never match the skip path in
`transactionToPayment`. Update the transfer translation helper to wrap
`currency.ErrMissingCurrencies` as `plugins.ErrCurrencyNotSupported` (matching
the payment path), and make sure the `Transfer` branch still surfaces that
wrapped error through `transactionToPayment` so the existing skip logic in
`payments.go` can continue. Add a test in `payments_test.go` covering a `Type:
"Transfer"` transaction with an unsupported currency to verify it is skipped
rather than aborting ingestion.

---

Nitpick comments:
In `@internal/connectors/plugins/public/increase/payments_test.go`:
- Around line 640-673: Add an explicit MinInt64 regression test in the same
mapPayment coverage alongside the existing large positive and negative amount
cases. The current tests in mapPayment only verify the 2^53+1 precision fix; add
a case using the exact MinInt64 boundary and assert the resulting payment amount
is preserved correctly without overflow when taking the absolute value. Use the
existing plg.mapPayment and payment.Amount assertions to cover this edge case.

In `@internal/connectors/plugins/public/plaid/payments_test.go`:
- Around line 86-127: The skipped-payment test in FetchNextPayments only asserts
empty payments and misses the ingestion-progress contract. Update the plaid
payments test around plg.FetchNextPayments to also verify cursor/state
advancement (NewState and HasMore) after skipping unsupported currencies, using
the same ListTransactions mock/NextCursor path. Add coverage for the
resp.Modified skip branch in
internal/connectors/plugins/public/plaid/payments.go so both skipped-row paths
still advance ingestion correctly.

In `@internal/connectors/plugins/public/stripe/payments_test.go`:
- Around line 233-242: The empty-page test for FetchNextPayments only checks
Payments and HasMore, but it does not verify that the pagination state advances
after skipping the unsupported row. Update the test around plg.FetchNextPayments
to return a non-empty client.Timeline from the mocked GetPayments call and
assert that the resulting res.NewState contains the serialized timeline state,
so the skip path in FetchNextPayments and its NewState handling are covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d6079f0-382c-4f93-8b14-bded520c6c97

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd83ca and 577661d.

📒 Files selected for processing (15)
  • internal/connectors/plugins/public/increase/payments.go
  • internal/connectors/plugins/public/increase/payments_test.go
  • internal/connectors/plugins/public/moneycorp/balances.go
  • internal/connectors/plugins/public/moneycorp/balances_test.go
  • internal/connectors/plugins/public/moneycorp/payments.go
  • internal/connectors/plugins/public/moneycorp/payments_test.go
  • internal/connectors/plugins/public/plaid/balances.go
  • internal/connectors/plugins/public/plaid/balances_test.go
  • internal/connectors/plugins/public/plaid/client/amount_utils.go
  • internal/connectors/plugins/public/plaid/payments.go
  • internal/connectors/plugins/public/plaid/payments_test.go
  • internal/connectors/plugins/public/stripe/payments.go
  • internal/connectors/plugins/public/stripe/payments_test.go
  • internal/connectors/plugins/public/wise/balances.go
  • internal/connectors/plugins/public/wise/balances_test.go

@codecov

codecov Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.74%. Comparing base (5dd83ca) to head (a8aa6fc).

Files with missing lines Patch % Lines
...ternal/connectors/plugins/public/plaid/payments.go 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #781      +/-   ##
==========================================
+ Coverage   65.72%   65.74%   +0.01%     
==========================================
  Files         859      859              
  Lines       39299    39324      +25     
==========================================
+ Hits        25831    25854      +23     
- Misses      11729    11735       +6     
+ Partials     1739     1735       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ch path (M-CON1)

Addresses PR review: a debit Transfer routes toPSPPayments ->
transactionToPayment -> fetchAndTranslateTransfer -> transferToPayment, which
returned the bare currency.ErrMissingCurrencies for an unsupported
TransferCurrency. The skip branch only catches plugins.ErrCurrencyNotSupported,
so those transfer rows still failed FetchNextPayments and retried forever.

Wrap the GetPrecision error in transferToPayment as plugins.ErrCurrencyNotSupported
(matching the payment path) so the existing fetch-loop skip applies. Added a
Type:"Transfer" unsupported-currency regression test. transferToPayment is also
used by createTransfer, but that path validates the asset upfront, so wrapping
is a no-op there.

Confidence: high
Scope-risk: narrow
Directive: transferToPayment is on the FETCH path (via fetchAndTranslateTransfer), not only create — currency errors there must be skippable

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumaryBot posted 2 new inline findings.

Summary: #781 (comment)


payment, err := p.transactionToPayment(ctx, transaction)
if err != nil {
if errors.Is(err, plugins.ErrCurrencyNotSupported) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 [major] Transfer path does not normalize unsupported-currency errors to plugins.ErrCurrencyNotSupported
reported by NumaryBot, coderabbitai

When a Moneycorp transaction is a debit Transfer, transactionToPayment delegates to fetchAndTranslateTransfer, which calls currency.GetPrecision in transfers.go. Unlike the payment path, this helper returns the raw currency.ErrMissingCurrencies without wrapping it into plugins.ErrCurrencyNotSupported. The new skip branch at line 103–108 only catches plugins.ErrCurrencyNotSupported, so Transfer rows with unsupported currencies still cause FetchNextPayments to fail and retry instead of being silently skipped.

Suggestion: In the transfer path (e.g., transferToPayment or its call site), wrap currency.ErrMissingCurrencies into plugins.ErrCurrencyNotSupported (using errors.Is/fmt.Errorf with the appropriate sentinel), so the skip branch at the payments level catches all unsupported-currency cases uniformly regardless of transaction type.

// Skip unsupported currencies rather than failing: a retryable
// error here would freeze ingestion for the whole account.
p.logger.WithField("transaction_id", transaction.ID).Info("skipping transaction with unsupported currency")
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 [major] Pagination watermark not advanced when all new rows are skipped due to unsupported currency

When the only new Moneycorp transactions (or the newest tail) all have unsupported currencies, the continue drops them from the returned payments slice. The caller advances LastCreatedAt based on payments[len(payments)-1], so the watermark remains unchanged. On the next poll, the same skipped rows are refetched and logged again, creating a permanent polling loop rather than truly skipping past those rows.

Suggestion: Track the timestamp/ID of the last-seen row (supported or not) separately from the list of returned payments, and always advance the watermark to the latest processed row even when all are skipped due to unsupported currencies.

@fguery
fguery added this pull request to the merge queue Jun 30, 2026
Merged via the queue into main with commit e55050c Jun 30, 2026
8 checks passed
@fguery
fguery deleted the fix/EN-1095_connector_currency_skip branch June 30, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants