Skip to content

fix(getUsdPrice): don't stop of first failure - #254

Merged
azebuado merged 2 commits into
mainfrom
fix/try-all-on-failure
Sep 1, 2026
Merged

fix(getUsdPrice): don't stop of first failure#254
azebuado merged 2 commits into
mainfrom
fix/try-all-on-failure

Conversation

@azebuado

@azebuado azebuado commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Another part of https://linear.app/cowswap/issue/FE-449/address-coingecko-fallback-issues-in-bff

Don't return a 500 on first 500 found. Try all repositories instead as one might have a price.

Details

Make fallback work on upstream errors, not just null, and stop caching upstream errors as "no price". Implemented together, since neither works alone: fixing only the fallback is inert because Coingecko failures never reach it as throws, and fixing only Coingecko would turn its errors straight into 500s.

  • UsdRepositoryFallback had a bare await per repository, so a throw aborted the loop and escaped as a 500 instead of trying the next source. A throw is now treated like a null and the next source is tried.

  • Both Coingecko response handlers short-circuited before throwIfUnsuccessful: a 429 or 5xx carries no price field, matched the !data?.[key]?.usd condition and returned null. That null was cached for the 30 minute NULL TTL, hid the outage behind a 404 long after recovery, and made the fallback log line count failures as unknown tokens. Only a 404 is now treated as an answer.

  • When no price is found and any source failed, the error is rethrown rather than reported as no price. Reason below in the notes: a 404 makes the frontend blacklist the token for the whole session, so an outage must never look like one.

  • UsdRepositoryCache needed no change, since cacheValue already sits after the await and a throw skips it. That was implicit and is now asserted in tests.

  • Watch after deploy: this deliberately converts a class of silent 404s into 5xx. Volume is unknown precisely because these failures have been recorded as nulls until now.

Testing

  • Unit tests
  • Ran coingecko e2e locally

Summary by CodeRabbit

  • Bug Fixes
    • Improved USD price handling when upstream pricing services experience errors.
    • Invalid or unsuccessful responses now surface as errors instead of being incorrectly treated as unavailable prices.
    • Confirmed that failed price lookups are not cached as missing values.
    • Fallback pricing sources are now tried more reliably, with failures recorded and successful results returned when available.
    • Missing prices, unavailable tokens, zero-valued prices, and not-found responses continue to be handled appropriately.

@azebuado
azebuado changed the base branch from main to fix/coingecko-platforms August 27, 2026 09:40
@azebuado azebuado self-assigned this Aug 27, 2026
@linear-code

linear-code Bot commented Aug 27, 2026

Copy link
Copy Markdown

FE-449

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 997471bc-cf37-400e-807f-4497fb2497d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 630fd99a-2d8f-4ba5-9c7e-ccee069613dc

📥 Commits

Reviewing files that changed from the base of the PR and between 484401f and d534380.

📒 Files selected for processing (5)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.spec.ts
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.spec.ts
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.ts
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.spec.ts
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change distinguishes CoinGecko failures from missing prices, centralizes repository fallback handling, and verifies that proxy failures are not cached.

Changes

USD repository failure handling

Layer / File(s) Summary
CoinGecko error semantics
libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.ts, libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.spec.ts
CoinGecko returns null for 404, missing token data, and zero prices. Other unsuccessful responses throw.
Fallback error orchestration
libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.ts, libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.spec.ts
getUsdPrice and getUsdPrices use firstNonNull, which continues after null results or errors, logs failures, and rethrows when no repository returns a price.
Cache failure validation
libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.spec.ts
Proxy errors propagate for single and multiple price lookups without calling redisMock.set.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to d5343

The PR improves price-source fallback behavior and prevents upstream failures from being cached as missing prices; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant UsdRepositoryFallback
  participant Repository
  participant logger

  Client->>UsdRepositoryFallback: request USD price
  UsdRepositoryFallback->>Repository: query repository
  Repository-->>UsdRepositoryFallback: price, null, or error
  UsdRepositoryFallback->>logger: log fallback event
  UsdRepositoryFallback->>Repository: query next repository when needed
  UsdRepositoryFallback-->>Client: return price, null, or error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: getUsdPrice now continues fallback processing after the first repository failure. It contains a minor grammatical error, but remains specific and understa…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5…
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.
Full details: Title check

Explanation

The title clearly identifies the main change: getUsdPrice now continues fallback processing after the first repository failure. It contains a minor grammatical error, but remains specific and understandable.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5 files.

✨ 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/try-all-on-failure

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.

@azebuado

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@azebuado
azebuado force-pushed the fix/try-all-on-failure branch from 7d6697d to e79e194 Compare September 1, 2026 15:16
Base automatically changed from fix/coingecko-platforms to main September 1, 2026 15:33
@azebuado
azebuado force-pushed the fix/try-all-on-failure branch from e79e194 to 944b674 Compare September 1, 2026 15:33
@azebuado
azebuado merged commit 93215bc into main Sep 1, 2026
8 checks passed
@azebuado
azebuado deleted the fix/try-all-on-failure branch September 1, 2026 15:37
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.

2 participants