Skip to content

feat: add exception when array is passed for 2nd arg #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/AsyncStorage.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ function checkValidInput(usedKey: string, value: any) {
}
}

function checkValidArgs(args: Array<Array<string>>) {
if (Array.isArray(args[1])) {
throw new Error(
'[AsyncStorage] Did you mean to pass an array of key value pairs instead? The second arguement to multiSet cannot be an array\n',
);
}
}

/**
* `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value
* storage system that is global to the app. It should be used instead of
Expand Down Expand Up @@ -322,6 +330,7 @@ const AsyncStorage = {
callback?: ?(errors: ?$ReadOnlyArray<?Error>) => void,
): Promise<null> {
return new Promise((resolve, reject) => {
checkValidArgs(arguments);
keyValuePairs.forEach(([key, value]) => {
checkValidInput(key, value);
});
Expand Down