Skip to content

Commit 09e7375

Browse files
authored
fix(ios): keep the original error message for script download failures (#1449)
1 parent b440b44 commit 09e7375

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Keep the original error message for iOS script download failures instead of surfacing "Unknown error from a native module".

‎packages/repack/ios/ScriptManager.mm‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ @interface RCTBridge (RCTTurboModule)
2626
static NSURLSession * (^_urlSessionFactory)(void) = nil;
2727
static NSURLSession *_cachedURLSession = nil;
2828

29+
// NSURLError instances fill in localizedDescription but leave localizedFailureReason nil.
30+
// Passing a nil message to the reject block makes React Native substitute
31+
// "Unknown error from a native module", which hides whether the download timed out,
32+
// lost the connection or failed TLS. Fall back to the description and append the
33+
// domain/code so the cause survives the bridge.
34+
static NSString *DescribeScriptDownloadError(NSError *error)
35+
{
36+
NSString *reason = error.localizedFailureReason ?: error.localizedDescription;
37+
if (reason.length == 0) {
38+
reason = @"Script download failed";
39+
}
40+
return [NSString stringWithFormat:@"%@ (%@ %ld)", reason, error.domain, (long)error.code];
41+
}
42+
2943
@implementation ScriptManager
3044

3145
RCT_EXPORT_MODULE()
@@ -88,7 +102,7 @@ - (NSURLSession *)urlSession
88102
[self downloadAndCache:config
89103
completionHandler:^(NSError *error) {
90104
if (error) {
91-
reject(ScriptDownloadFailure, error.localizedFailureReason, nil);
105+
reject(ScriptDownloadFailure, DescribeScriptDownloadError(error), error);
92106
} else {
93107
[self execute:config resolve:resolve reject:reject];
94108
}
@@ -139,7 +153,7 @@ - (NSURLSession *)urlSession
139153
[self downloadAndCache:config
140154
completionHandler:^(NSError *error) {
141155
if (error) {
142-
reject(ScriptDownloadFailure, error.localizedFailureReason, nil);
156+
reject(ScriptDownloadFailure, DescribeScriptDownloadError(error), error);
143157
} else {
144158
resolve(nil);
145159
}

0 commit comments

Comments
 (0)