question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncStorage Couldn't read row 0, col 0 from CursorWindow

See original GitHub issue

This issue was originally created by @JAStanton as facebook/react-native#12529.


Description

When reading values that are too large using AsyncStorage on Android I run into this error:

I wrote a large value with AsyncStorage and later tried to read it, but it crashed.

BaseError: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  at e (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:423:22)
  at None (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:416:71)
  at map ([native code])
  at errors (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:416:51)
  at slicedToArray (/node_modules/react-native/Libraries/Storage/AsyncStorage.js:54:33)

Reproduction

It looks like on iOS we write to disk when the value is above a threshold and on Android we write to sqllite always.

let x = 'x';
while (x.length <= 3194304) {
  x = `${x}${x}`;
}
await AsyncStorage.setItem('@@GARBAGE@@', x); // works
const garbage = await AsyncStorage.getItem('@@GARBAGE@@'); // throws

Solution

In order for me to fix this I’ll need to re-write AsyncStorage to write to disk instead of writing to sql. https://github.com/mvayngrib/react-native-safe-async-storage <— this guys has the right idea but his code is super old and broken.

Additional Information

  • React Native version: 0.39.2
  • Platform: Android
  • Operating System: Samsung Galaxy S4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
sergiosbxcommented, Mar 21, 2019

Workaround:

async getSafeItem(key) {
  return new Promise((resolve, reject) => {
    if (!key) {
      reject('Invalid key');
    }
    AsyncStorage.getItem(createKey(key)).then((value) => {
      resolve(value);
    }, () => {// Couldn't read row 0, col 0 from CursorWindow
      resolve(null); // Force not to break
    });
  });
}

Additional Information

  • React Native version: 0.57.0
  • Platform: Android
  • Operating System: All Motorola devices
1reaction
krizzucommented, Mar 26, 2019

@juliopiubello Because this whole module is about AS. Since everything is related I just remove redundant labels

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncStorage Couldn't read row 0, col 0 from CursorWindow
I wrote a large value with AsyncStorage and later tried to read it, but it crashed. BaseError: Couldn't read row 0, col 0...
Read more >
Couldn't read row 0, col 0 from CursorWindow. (After app ...
Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 64 columns. The cursor does not contain any rows....
Read more >
react-native-safe-async-storage-af - npm package - Snyk
IllegalStateException: Couldn't read row 0, col 0 from CursorWindow" when large values are stored using AsyncStorage. Usage. npm install --save ...
Read more >
react-native-safe-async-storage-af: Docs & Community
react-native-safe-async-storage-af documentation and community, ... IllegalStateException: Couldn't read row 0, col 0 from CursorWindow" when large values ...
Read more >
Crash in java.lang.IllegalStateException: Couldn''t read row 0 ...
IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found