always pass key parameter to RCTReadFile

Differential Revision: D5921064

fbshipit-source-id: ad2dd352060fcb2c873dc5a91781797c9abd6c33
This commit is contained in:
Alex Dvornikov 2017-09-28 09:22:16 -07:00 committed by Facebook Github Bot
parent 652dfd0b48
commit c4f7ce9afd
1 changed files with 12 additions and 6 deletions

View File

@ -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);