Skip to content

fix: Prevent TypeError from caching API error responses - #170

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/typeerror-map-on-non-array
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/typeerror-map-on-non-array

Conversation

@sentry

@sentry sentry Bot commented Sep 27, 2026

Copy link
Copy Markdown

This PR addresses a TypeError: .map is not a function occurring in getComponents (and potentially getFlags) when the Codecov browser extension attempts to process cached API responses.

Root Cause:
Previously, src/service.ts unconditionally cached API responses, including error objects (e.g., JSON bodies from 404, 403, or 429 HTTP statuses). When these cached error objects were retrieved, they were returned with ok: true, leading src/content/github/common/fetchers.ts to incorrectly assume the response.data was an array and attempt to call .map() on it, resulting in the TypeError.

Solution:

  1. Prevent caching of error responses: In src/service.ts, the calls to setCached within listFlags and listComponents are now guarded by response.ok. This ensures that only successful API responses are stored in the cache, preventing error objects from being treated as valid data.
  2. Defense-in-depth with Array.isArray() checks: In src/content/github/common/fetchers.ts, Array.isArray() checks have been added before calling .map() in both getComponents and getFlags. This provides an additional layer of protection, ensuring that .map() is only ever called on actual arrays, even if a non-array value were to somehow reach these functions.

This fix aligns with the proposed solution in PR #164.

Fixes BROWSER-EXTENSION-DW

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 149 bytes (0.02%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
codecov-browser-extension-array-push 660.61kB 149 bytes (0.02%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: codecov-browser-extension-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
background.js 101 bytes 207.76kB 0.05%
githubFile.js 48 bytes 11.51kB 0.42%

Files in githubFile.js:

  • ./src/content/github/common/fetchers.ts → Total Size: 2.55kB

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.

0 participants