react-native: NSNull Length exception thrown while invoking multiSet on target AsyncLocalStorage - unhandled exception crashes app on iOS

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: Win 10 1703 OS Build: 15063.674 Node: 4.6.1 Yarn: – npm: 5.5.1 Watchman: – Xcode: – Android Studio: –

"expo": "^22.0.2",
"react": "16.0.0-beta.5",
"react-native": "^0.49.5",
"react-native-auth0": "^1.2.1",
"react-native-canvas": "^0.1.20",
"react-native-maps": "^0.17.1",
"react-navigation": "^1.0.0-beta.19"

Target Platform: iOS (11)

Steps to Reproduce

NSNull unhandled exception leading to total application crash when attempting to call AsyncStorage.setItem(‘justAString’).

Cannot try/catch/finally to prevent crash, suggest adding exception handler.

Expected Behavior

An error message should have been thrown with the promise associated with setItem.

Actual Behavior

Expo displays this exception and stack trace for less than a second before crashing the Expo instance. image

Reproducible Demo

import React, { Component } from 'react';
import { AsyncStorage } from 'react-native';

replaceLocal('StringParam')

export async function replaceLocal(key,newObj){
    try {
        let stringObject = JSON.stringify(newObj)
        AsyncStorage.setItem(key,stringObject)
    } catch (error) {
        console.log(error)
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 15

Most upvoted comments

We eliminated this issue in our RN codebase at comma.ai by ensuring we never setItem(key, null).

Not sure if this qualifies as a bug given the AsyncStorage.setItem is documented to expect a non-null string value parameter.

Same here. It works fine when loading build in expo but fails in TestFlight. Values are empty strings.

I am having this exact same issue. I already check that the value being stored isn’t null

hi,

using JSON.stringify(value) solved my problem.

AsyncStorage.setItem(“myKey”, JSON.stringify(“myValue”));

I am having this same issue while storing a json file in the async and then using it later. Is there any way to get past this