From 156a9a29a9c587691cb88103fd7a04e25d971ed7 Mon Sep 17 00:00:00 2001 From: generatedunixname1608173377072046 Date: Tue, 8 Sep 2026 07:33:49 -0700 Subject: [PATCH] Include errno in iOS bundle open/stat failure messages (#58383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/react/react-native/pull/58383 When `RCTJavaScriptLoader` fails to open or stat the JS bundle, the resulting `NSError` carried only the bundle path. The `errno` set by the failing `fopen()` / `stat()` was discarded, so a bundle that is absent (`ENOENT`) was indistinguishable from one that exists but cannot be read (`EACCES`, `EIO`). Because `RCTInstance handleBundleLoadingError:` turns every loader error into a fatal, this is the only diagnostic information available after the fact — and there was none. Capture `errno` immediately after the failing call (before any intervening call can clobber it) and surface it in two ways: appended to the localized description as `(errno : )`, which is what ends up in the crash report, and as an `NSPOSIXErrorDomain` error under `NSUnderlyingErrorKey` for programmatic consumers. Purely additive to error paths that already abort; no behavior change on success. Changelog: [iOS][Changed] - Include `errno` and its description in `RCTJavaScriptLoader` bundle open/stat errors Reviewed By: javache Differential Revision: D118952499 fbshipit-source-id: 6f711dde3969f9fdcd1af300121d954a2da8816e --- .../React/Base/RCTJavaScriptLoader.mm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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;