Log swallowed Brex import failures to the debug log
JA
5d ago+179+179+012345678901234567890123456789-1-1-0123456789
Summary
Provider kit follow-up: BrexItem::Importer rescued its per-call failures and only wrote them to Rails.logger, so a partly failed Brex import left nothing in /settings/debug. AGENTS.md asks for DebugLogEntry.capture for support-relevant failures and partial responses.
Closes jaysbeekay/sure#816. Part of jaysbeekay/sure#670 (provider kit).
Stacked on jaysbeekay/sure#924. Upstream draft PR: https://github.com/we-promise/sure/pull/5479 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit. Appended to fork stack #687.
What changed
- One private helper,
capture_import_failure, is called at each fetch and import rescue that swallows an error: the accounts fetch (bad format,BrexError, parse, unexpected), one account's import, and one account's transactions (bad format,BrexError, parse, unexpected, and the per-account rescue around it).mark_requires_update_if_credentials_errorstill only logs a failure of its own status update. - Each entry records
provider_key: "brex"and the family. A transactions failure also records the Brex account's link; an account-import failure records only the account id, since that account may not be linked yet. - Its metadata holds
brex_item_id,account_id,error_class,error_messageandtrace_id, with blanks dropped. - Credential errors are re-raised without a capture here. The kit syncer already logs them (
provider_sync_error), so capturing here too would record each one twice. The snapshot-store failure re-raises and is left to the syncer for the same reason. - Return values are unchanged.
Verification
- Fail-first: a failed accounts fetch and a failed transactions fetch each add one entry with the exact metadata; before the change they added none. A failed account import carries its account id in the metadata. Each of the other seven capture sites has its own test: the accounts fetch's non-Hash response, parse error and unexpected error, the same three for a transactions fetch, and the per-account transactions rescue.
- Guards:
- a 401 during a sync adds exactly one entry, the syncer's;
- a clean import adds none.
- Mutations, each caught: removing either capture, capturing before the credential re-raise, dropping
trace_id, dropping the account link, and droppingaccount_id. bin/rails test(full, at e3ab39fc0): 16620 runs, 0 failures (8ReleaseNotesWorkflowTestenvironment errors). rubocop clean. Non-test diff +31 / -0; +179 / -1 with tests.
Migration notes
No migration.