Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lszomoru
Copy link
Member

@lszomoru lszomoru commented Nov 4, 2025

Fixes #275089

Copilot AI review requested due to automatic review settings November 4, 2025 15:31
@lszomoru lszomoru enabled auto-merge (squash) November 4, 2025 15:31
@lszomoru lszomoru self-assigned this Nov 4, 2025
@lszomoru lszomoru added the scm General SCM compound issues label Nov 4, 2025
@lszomoru lszomoru added this to the October 2025 milestone Nov 4, 2025
Copy link
Contributor

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 defensive checks to prevent array index access errors when creating incoming/outgoing changes nodes in the SCM history graph. The changes guard against scenarios where the merge base history item might not be loaded yet.

Key changes:

  • Added validation to check that both beforeHistoryItemIndex and afterHistoryItemIndex are valid (-1 check) before accessing array elements
  • Updated comments to clarify that indices might not be found if history items are not yet loaded
  • Wrapped the incoming and outgoing changes node creation logic in conditional blocks

// Create incoming changes node
const inputSwimlanes = viewModels[beforeHistoryItemIndex].outputSwimlanes.map(i => deepClone(i));
const outputSwimlanes = viewModels[afterHistoryItemIndex].inputSwimlanes.map(i => deepClone(i));
const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0;
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Potential array access error: viewModels[0] can throw if the array is empty. Although the function builds viewModels from historyItems, this code is inside a guard that only checks beforeHistoryItemIndex !== -1 && afterHistoryItemIndex !== -1, which doesn't guarantee the array is non-empty. Consider adding a check viewModels.length > 0 or using optional chaining: viewModels[0]?.historyItem.displayId?.length ?? 0.

Suggested change
const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0;
const displayIdLength = viewModels[0]?.historyItem.displayId?.length ?? 0;

Copilot uses AI. Check for mistakes.
})
: [];
const outputSwimlanes = viewModels[afterHistoryItemIndex].inputSwimlanes.slice(0);
const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0;
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Potential array access error: viewModels[0] can throw if the array is empty. Although the function builds viewModels from historyItems, this code is inside a guard that only checks afterHistoryItemIndex !== -1, which doesn't guarantee the array is non-empty. Consider adding a check viewModels.length > 0 or using optional chaining: viewModels[0]?.historyItem.displayId?.length ?? 0.

Suggested change
const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0;
const displayIdLength = viewModels[0]?.historyItem.displayId?.length ?? 0;

Copilot uses AI. Check for mistakes.
@lszomoru lszomoru merged commit d271140 into main Nov 4, 2025
33 of 34 checks passed
@lszomoru lszomoru deleted the lszomoru/cool-panther branch November 4, 2025 15:50
amubushar pushed a commit to amubushar/vscode that referenced this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scm General SCM compound issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCM Graph not refreshing - TypeError: Cannot read properties of undefined (reading 'inputSwimlanes')

3 participants