Show an import's own error text when it fails without counts

Merged
JA
1d ago
+24-1

Summary

Provider kit Track B, K1: when an import fails without per-account counts but its result carries error text, the shared syncer now reports that text instead of a generic "import failed". This is a behaviour change for Brex, the only provider on the kit so far. It is the first convergence step towards moving Lunch Flow and Mercury onto the kit, which report the provider's error today.

Part of #5003 (Track B, convergence decisions, 2026-11-16).

Stacked on #5235. Fork pre-flight: jaysbeekay/sure#725 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

Behaviour delta (Brex)

Import resultBeforeAfter
success: false with error: "…" and no per-account counts"Brex import failed.""Brex import failed: …"

Brex's importer rescues BrexError and returns the constant "Failed to fetch accounts data", so today a Brex user sees "Brex import failed: Failed to fetch accounts data", not the provider's own text. Lunch Flow and Mercury pass their provider's text when they move onto the kit. A cap on that text (length, no URLs or tokens) is a follow-up issue, decided before B7/B8.
| success: false with no error text | "Brex import failed." | unchanged |
| per-account or per-transaction failure counts | the count messages | unchanged |

The error category stays import_error. The new message key, brex_items.syncer.import_failed_with_error, is in en only; other locales fall back to English for this one message, which is the existing fallback behaviour.

What changed

  • ProviderItem::Syncer#import_result_errors: with no count failures, it uses <key>_items.syncer.import_failed_with_error (with the provider's text) when the result has an error, and import_failed otherwise.
  • config/locales/views/brex_items/en.yml: the new key.

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Contract (fail-first): ProviderItemLifecycleTests adds "a failed import reports the provider's own error when it gives one". It asserts both messages: with the provider's text, and the unchanged generic message without it. Before the change it fails, because the syncer ignored the result's error text ("Brex import failed."). Since 2026-11-17 it also runs error: "" and expects the generic message, so key?(:error) in place of present? fails it.
  • Mutations, each caught: never using the provider's text; always using it.
  • bin/rails test (full, at the K1 commit): 16,305 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings.
  • Diff: non-test +4 / -1.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • ProviderItem::Syncer serves only Brex today. Lunch Flow and Mercury adopt it in their convergence slices, which already show the provider's text.

Summary by cubic

Shows a provider's own error text when an import fails without per-account or per-transaction counts, instead of the generic "import failed" message.

ProviderItem::Syncer now reports the provider's error text through the new <key>_items.syncer.import_failed_with_error locale key when a failed import carries an error, falling back to the generic import_failed message when the error is blank, including an empty string. The category stays import_error. The new test covers both paths: a provider-supplied error and a blank one. This changes Brex, the only provider on the kit, and is the first convergence step toward moving Lunch Flow and Mercury onto the kit, which already report the provider's own text. Part of #5003.