Skip to content

fix: add null check for regex match to prevent "Cannot read properties of undefined" error #6097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Jul 23, 2025

Fixes #6096

Summary

This PR fixes the "Cannot read properties of undefined (reading '0')" error that occurs during retry attempts when handling 429 rate limit errors with Gemini API retry details.

Changes

  • Added proper null check for match[1] before accessing it in Task.ts line 1835
  • The regex match can return null when the pattern doesn't match, which was causing the error

Testing

  • Added comprehensive test coverage for the 429 retry logic with Gemini error details
  • Tests cover three scenarios:
    1. Valid retry delay format (e.g., "10s")
    2. Invalid retry delay format (e.g., "invalid")
    3. Missing retry delay property

Technical Details

The issue occurred when the code tried to parse the retry delay from Gemini error details:

const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
if (match) {  // This check was insufficient
    exponentialDelay = Number(match[1]) + 1  // Error here when match is null
}

Now fixed to:

const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
if (match && match[1]) {  // Added null check for match[1]
    exponentialDelay = Number(match[1]) + 1
}

Important

Fixes a "Cannot read properties of undefined" error in Task.ts by adding a null check for regex matches, with tests for various retry scenarios.

  • Behavior:
    • Fixes "Cannot read properties of undefined (reading '0')" error in Task.ts by adding a null check for match[1] in line 1835.
    • Handles cases where regex match returns null due to non-matching patterns.
  • Testing:
    • Adds tests in Task.spec.ts for 429 retry logic with Gemini error details.
    • Tests cover valid, invalid, and missing retry delay formats.
  • Technical Details:
    • Updates regex match logic in Task.ts to include a null check for match[1] to prevent errors when accessing undefined properties.

This description was created by Ellipsis for f23b27a. You can customize this summary. It will automatically update as commits are pushed.

…s of undefined" error

- Added proper null check for match[1] before accessing it in Task.ts line 1835
- Added comprehensive test coverage for 429 retry logic with Gemini error details
- Fixes issue #6096 where undefined match result caused runtime error
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 23, 2025 06:34
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 23, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 23, 2025
@daniel-lxs
Copy link
Collaborator

The author closed the issue as completed, see #6096 (comment)

@daniel-lxs daniel-lxs closed this Jul 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 23, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Cannot read properties of undefined (reading '0') Retry attempt 1 Retrying now...
3 participants