Skip to content

Conversation

@marklearst
Copy link
Owner

…al backoff

Add withRetry() higher-order function that wraps async operations with automatic retry logic, exponential backoff, and rate limit awareness.

Features:

  • Configurable maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs
  • Respects Figma API Retry-After header for rate limit errors (429)
  • Optional retryOnlyRateLimits flag (default: true)
  • onRetry callback for logging/UI updates
  • Exponential backoff with configurable multiplier
  • Delay capped at maxDelayMs to prevent excessive waits

Usage:
import { withRetry, fetcher } from '@figma-vars/hooks';

const fetchWithRetry = withRetry( () => fetcher(url, token), { maxRetries: 3, onRetry: (attempt, delay) => console.log(Retry ${attempt} in ${delay}ms) } );

const data = await fetchWithRetry();

Changes:

  • src/utils/retry.ts: New withRetry function with RetryOptions interface
  • src/utils/index.ts: Export withRetry and RetryOptions
  • tests/utils/retry.test.ts: 16 tests covering all retry scenarios

Test coverage: 100%

Refs: Codex Audit Item #16

…al backoff

Add withRetry() higher-order function that wraps async operations with
automatic retry logic, exponential backoff, and rate limit awareness.

Features:
- Configurable maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs
- Respects Figma API Retry-After header for rate limit errors (429)
- Optional retryOnlyRateLimits flag (default: true)
- onRetry callback for logging/UI updates
- Exponential backoff with configurable multiplier
- Delay capped at maxDelayMs to prevent excessive waits

Usage:
  import { withRetry, fetcher } from '@figma-vars/hooks';

  const fetchWithRetry = withRetry(
    () => fetcher(url, token),
    {
      maxRetries: 3,
      onRetry: (attempt, delay) => console.log(`Retry ${attempt} in ${delay}ms`)
    }
  );

  const data = await fetchWithRetry();

Changes:
- src/utils/retry.ts: New withRetry function with RetryOptions interface
- src/utils/index.ts: Export withRetry and RetryOptions
- tests/utils/retry.test.ts: 16 tests covering all retry scenarios

Test coverage: 100%

Refs: Codex Audit Item #16
Copilot AI review requested due to automatic review settings December 30, 2025 00:45
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.28%. Comparing base (401cf69) to head (14773c9).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/retry.ts 97.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   90.98%   91.28%   +0.30%     
==========================================
  Files          35       36       +1     
  Lines         943      987      +44     
  Branches      267      284      +17     
==========================================
+ Hits          858      901      +43     
- Misses         84       85       +1     
  Partials        1        1              
Flag Coverage Δ
unittests 91.28% <97.72%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a withRetry utility function that wraps async operations with automatic retry logic, exponential backoff, and rate limit awareness. The implementation provides a robust solution for handling transient failures, particularly Figma API rate limiting (HTTP 429 errors).

Key Changes:

  • New withRetry higher-order function with configurable retry behavior including exponential backoff, max retries, and delay limits
  • Respects Retry-After headers from rate limit errors and provides optional callback for retry events
  • Comprehensive test suite with 16 test cases achieving 100% code coverage

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/utils/retry.ts Core implementation of withRetry function and RetryOptions interface with exponential backoff logic and rate limit handling
src/utils/index.ts Exports withRetry function and RetryOptions type for public API access
tests/utils/retry.test.ts Comprehensive test suite covering successful execution, rate limit handling, retry options, callbacks, and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marklearst marklearst merged commit f24002b into main Dec 30, 2025
10 checks passed
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