Skip to content

fix(predict): Guards against undefined tags being returned from search endpoint#24266

Merged
matallui merged 2 commits intomainfrom
fix/predict-search-empty
Jan 6, 2026
Merged

fix(predict): Guards against undefined tags being returned from search endpoint#24266
matallui merged 2 commits intomainfrom
fix/predict-search-empty

Conversation

@kevinbluer
Copy link
Copy Markdown
Contributor

@kevinbluer kevinbluer commented Jan 6, 2026

Description

This PR fixes an issue where certain search queries in Predict would return no results despite the API returning valid data.

Reason for change:
When users searched for terms like "nhl", the app would display no results even though the search API returned valid events. Some events had their tags field set to undefined instead of an empty array, causing array method calls to throw. These errors were caught and silently returned an empty array, resulting in "no results" displayed to users.

Solution:
Added defensive checks to safely handle undefined or non-array tags. This ensures malformed events don't crash parsing and valid markets are still displayed. Applied the same pattern to the markets field.

Changelog

CHANGELOG entry: Fixes issue where certain search queries in Predict would return no results

Related issues

Fixes: PRED-414

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

image

After

image

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Improves resilience of Polymarket market parsing and search results handling.

  • Guard isSportEvent against non-array tags; treat missing tags as empty
  • In sortMarkets, treat non-array markets as empty and respect event.sortBy
  • In parsePolymarketEvents, default missing tags to [], ignore inactive markets defensively, and continue parsing
  • In getParsedMarketsFromPolymarketApi, normalize response (events/data) to arrays and, for search (q), return only events with outcomes; remove extraneous logging
  • Tests: add cases for missing markets (returns []) and missing tags (yields empty tags)

Written by Cursor Bugbot for commit 0cbcfd6. This will update automatically on new commits. Configure here.

@metamaskbot metamaskbot added the team-predict Predict team label Jan 6, 2026
@github-actions github-actions bot added the size-M label Jan 6, 2026
@kevinbluer kevinbluer marked this pull request as ready for review January 6, 2026 18:50
@kevinbluer kevinbluer requested a review from a team as a code owner January 6, 2026 18:50
@kevinbluer kevinbluer added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Jan 6, 2026
@kevinbluer kevinbluer force-pushed the fix/predict-search-empty branch from 2956fb7 to 0cbcfd6 Compare January 6, 2026 19:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 6, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions
  • Risk Level: low
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

The changes are in app/components/UI/Predict/providers/polymarket/utils.ts and its test file. The modifications are defensive coding improvements that add Array.isArray() checks to handle edge cases where API responses might have undefined/non-array values for tags, markets, and events fields.

Specific changes:

  1. isSportEvent(): Now safely handles when event.tags is undefined
  2. sortMarkets(): Now safely handles when event.markets is undefined
  3. parsePolymarketEvents(): Now safely handles when event.tags is undefined
  4. getParsedMarketsFromPolymarketApi(): Now safely handles when API response data is not an array, and filters out markets with no outcomes when searching

These are low-risk defensive improvements that don't change core business logic - they just add safety checks to prevent runtime errors when API responses have unexpected shapes. The test file adds corresponding test cases to verify these edge cases are handled correctly.

The SmokePredictions tag is the appropriate choice as it covers "Predictions features, prediction market" which directly maps to the Polymarket prediction market provider being modified.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jan 6, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@matallui matallui added this pull request to the merge queue Jan 6, 2026
Merged via the queue into main with commit 03a88bc Jan 6, 2026
161 of 164 checks passed
@matallui matallui deleted the fix/predict-search-empty branch January 6, 2026 22:23
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2026
@metamaskbot metamaskbot added the release-7.62.0 Issue or pull request that will be included in release 7.62.0 label Jan 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.62.0 Issue or pull request that will be included in release 7.62.0 size-M skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants