Skip to content

Isolate per-source failures during sync - #12

Open
ctrlaltdylan wants to merge 1 commit into
add-compare-command-and-fix-duplicatesfrom
fix/sync-graceful-source-errors
Open

Isolate per-source failures during sync#12
ctrlaltdylan wants to merge 1 commit into
add-compare-command-and-fix-duplicatesfrom
fix/sync-graceful-source-errors

Conversation

@ctrlaltdylan

Copy link
Copy Markdown
Owner

Problem

Running mrrmaid sync when one source has invalid credentials crashed the whole command with a raw traceback — even if another source was configured correctly. In practice this showed up as a Shopify 404 Client Error (from leftover placeholder creds like SHOPIFY_ORGANIZATION_ID=a) aborting a sync that only needed Stripe.

Root cause: sync_all called each source's sync unguarded, so the first exception propagated all the way up.

Change

  • DataSyncService.sync_all now syncs each source independently and returns (results, errors) — successes keep their record counts, failures are captured per source ("shopify" / "stripe") with their message.
  • The sync CLI prints a clean per-source warning, still renders the results table for sources that succeeded, and exits non-zero only when every configured source failed.

Before → after (bad Shopify creds + valid Stripe):

# before: full Rich traceback, Stripe never syncs, exit code from crash
# after:
⚠ Shopify sync failed: 404 Client Error: Not Found for url: https://partners.shopify.com/a/api/2026-01/graphql.json
        Sync Results
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Source                ┃ Records ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ Stripe Subscriptions  │ …       │
└───────────────────────┴─────────┘

Tests

tests/test_sync_error_isolation.py:

  • Shopify failure doesn't block Stripe (and is reported as an error).
  • Stripe failure doesn't block Shopify.
  • An unconfigured (None) source is skipped — neither a result nor an error.
$ python -m pytest tests/ -q
5 passed

Also manually verified end-to-end: a bad Shopify + bad Stripe config now prints two warnings + All configured sources failed to sync. and exits 1, with no traceback.

🤖 Generated with Claude Code

`sync_all` ran each source's sync unguarded, so a single API error (e.g.
invalid or placeholder Shopify credentials returning a 404) aborted the
entire command with a raw traceback — even when another source like
Stripe was configured correctly.

Sync each source independently and collect failures: `sync_all` now
returns `(results, errors)`. The CLI prints a clean per-source warning,
still shows results for sources that succeeded, and exits non-zero only
when every configured source failed.

Add tests covering source-failure isolation in both directions and the
skipped-source (None client) case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant