Log swallowed Brex import failures to the debug log
Merged
JA
2d 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.
Part of #5003.
Stacked on #5478. Fork pre-flight: jaysbeekay/sure#925 (same branch, same commit). Fork issue: jaysbeekay/sure#816.
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.
Summary by cubic
Logs swallowed Brex import failures so a partly failed import now leaves entries in /settings/debug for support to see.
- Calls a new private helper,
capture_import_failure, at every rescue that swallows an error: accounts fetch, per-account import, and per-account transactions. - Each entry records the
"brex"provider key, the family, and the Brex account link when there is one; metadata holdsbrex_item_id,account_id,error_class,error_message, andtrace_id, with blanks dropped. - Credential errors and snapshot-store failures are still re-raised without a capture because the kit syncer already logs them once each.
- Tests pin each of the seven capture sites to exactly one entry, and a 403 on transactions must yield exactly one entry, from the syncer, so a capture placed above the credential re-raise can't log the failure twice.
- Return values are unchanged.