From bef87b648c4bed228f1c5889abe0181a271edf76 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Mon, 12 Aug 2019 04:25:03 -0700 Subject: [PATCH] improve VirtualizedList error message (#25973) 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: https://github.com/facebook/react-native/pull/25973 Test Plan: not needed, tests must pass Differential Revision: D16708522 Pulled By: osdnk fbshipit-source-id: 8dfcbd95ff0f42805dbe32cd57969a93aea55add --- Libraries/Lists/VirtualizedList.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 4b3c3ebd4479bf..7dffc1729ef26c 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -338,7 +338,9 @@ class VirtualizedList extends React.PureComponent { 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(