From c4f7ce9afdea41fb64b6246894840873bf524d98 Mon Sep 17 00:00:00 2001 From: Alex Dvornikov Date: Thu, 28 Sep 2017 09:22:16 -0700 Subject: [PATCH] always pass key parameter to RCTReadFile Differential Revision: D5921064 fbshipit-source-id: ad2dd352060fcb2c873dc5a91781797c9abd6c33 --- React/Modules/RCTAsyncLocalStorage.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/React/Modules/RCTAsyncLocalStorage.m b/React/Modules/RCTAsyncLocalStorage.m index 34442779b..1064e04f2 100644 --- a/React/Modules/RCTAsyncLocalStorage.m +++ b/React/Modules/RCTAsyncLocalStorage.m @@ -51,14 +51,20 @@ static NSString *RCTReadFile(NSString *filePath, NSString *key, NSDictionary **e NSError *error; NSStringEncoding encoding; NSString *entryString = [NSString stringWithContentsOfFile:filePath usedEncoding:&encoding error:&error]; + NSDictionary *extraData = @{@"key": RCTNullIfNil(key)}; + if (error) { - *errorOut = RCTMakeError(@"Failed to read storage file.", error, @{@"key": key}); - } else if (encoding != NSUTF8StringEncoding) { - *errorOut = RCTMakeError(@"Incorrect encoding of storage file: ", @(encoding), @{@"key": key}); - } else { - return entryString; + if (errorOut) *errorOut = RCTMakeError(@"Failed to read storage file.", error, extraData); + return nil; } + + if (encoding != NSUTF8StringEncoding) { + if (errorOut) *errorOut = RCTMakeError(@"Incorrect encoding of storage file: ", @(encoding), extraData); + return nil; + } + return entryString; } + return nil; } @@ -235,7 +241,7 @@ RCT_EXPORT_MODULE() } if (!_haveSetup) { NSDictionary *errorOut; - NSString *serialized = RCTReadFile(RCTGetManifestFilePath(), nil, &errorOut); + NSString *serialized = RCTReadFile(RCTGetManifestFilePath(), RCTManifestFileName, &errorOut); _manifest = serialized ? RCTJSONParseMutable(serialized, &error) : [NSMutableDictionary new]; if (error) { RCTLogWarn(@"Failed to parse manifest - creating new one.\n\n%@", error);