Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ios-script-download-error-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Keep the original error message for iOS script download failures instead of surfacing "Unknown error from a native module".
18 changes: 16 additions & 2 deletions packages/repack/ios/ScriptManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ @interface RCTBridge (RCTTurboModule)
static NSURLSession * (^_urlSessionFactory)(void) = nil;
static NSURLSession *_cachedURLSession = nil;

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

@implementation ScriptManager

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -88,7 +102,7 @@ - (NSURLSession *)urlSession
[self downloadAndCache:config
completionHandler:^(NSError *error) {
if (error) {
reject(ScriptDownloadFailure, error.localizedFailureReason, nil);
reject(ScriptDownloadFailure, DescribeScriptDownloadError(error), error);
} else {
[self execute:config resolve:resolve reject:reject];
}
Expand Down Expand Up @@ -139,7 +153,7 @@ - (NSURLSession *)urlSession
[self downloadAndCache:config
completionHandler:^(NSError *error) {
if (error) {
reject(ScriptDownloadFailure, error.localizedFailureReason, nil);
reject(ScriptDownloadFailure, DescribeScriptDownloadError(error), error);
} else {
resolve(nil);
}
Expand Down