Skip to content

Commit

Permalink
improve VirtualizedList error message (#25973)
Browse files Browse the repository at this point in the history
Summary:
Motivation: when you receive error like `scrollToIndex out of range: 5 vs -1` it's not immediately clear if I requested 5 or -1. This will make the error a little easier to understand.

## Changelog

not needed
Pull Request resolved: #25973

Test Plan: not needed, tests must pass

Differential Revision: D16708522

Pulled By: osdnk

fbshipit-source-id: 8dfcbd95ff0f42805dbe32cd57969a93aea55add
  • Loading branch information
vonovak authored and facebook-github-bot committed Aug 12, 2019
1 parent 9b0adb5 commit bef87b6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const {animated, index, viewOffset, viewPosition} = params;
invariant(
index >= 0 && index < getItemCount(data),
`scrollToIndex out of range: ${index} vs ${getItemCount(data) - 1}`,
`scrollToIndex out of range: requested index ${index} but maximum is ${getItemCount(
data,
) - 1}`,
);
if (!getItemLayout && index > this._highestMeasuredFrameIndex) {
invariant(
Expand Down

0 comments on commit bef87b6

Please sign in to comment.