diff --git a/packages/react-native/React/Base/RCTJavaScriptLoader.mm b/packages/react-native/React/Base/RCTJavaScriptLoader.mm index 0cebb4b843e..9a42d933a1f 100755 --- a/packages/react-native/React/Base/RCTJavaScriptLoader.mm +++ b/packages/react-native/React/Base/RCTJavaScriptLoader.mm @@ -7,6 +7,8 @@ #import "RCTJavaScriptLoader.h" +#import +#import #import #import @@ -138,12 +140,20 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) // modules into JSC as they're required. FILE *bundle = fopen(scriptURL.path.UTF8String, "r"); if (!bundle) { + // Read errno before anything else can clobber it. Without it a missing bundle (ENOENT) is + // indistinguishable from one that exists but cannot be read (EACCES, EIO), which is the + // difference between a packaging bug and a transient filesystem failure. + const int openErrno = errno; if (error) { *error = [NSError errorWithDomain:RCTJavaScriptLoaderErrorDomain code:RCTJavaScriptLoaderErrorFailedOpeningFile userInfo:@{ - NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Error opening bundle %@", scriptURL.path] + NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Error opening bundle %@ (errno %d: %s)", + scriptURL.path, + openErrno, + strerror(openErrno)], + NSUnderlyingErrorKey : [NSError errorWithDomain:NSPOSIXErrorDomain code:openErrno userInfo:nil] }]; } return nil; @@ -190,12 +200,17 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) struct stat statInfo; if (stat(scriptURL.path.UTF8String, &statInfo) != 0) { + const int statErrno = errno; if (error) { *error = [NSError errorWithDomain:RCTJavaScriptLoaderErrorDomain code:RCTJavaScriptLoaderErrorFailedStatingFile userInfo:@{ - NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Error stating bundle %@", scriptURL.path] + NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Error stating bundle %@ (errno %d: %s)", + scriptURL.path, + statErrno, + strerror(statErrno)], + NSUnderlyingErrorKey : [NSError errorWithDomain:NSPOSIXErrorDomain code:statErrno userInfo:nil] }]; } return nil;