Fix crash in RCTExceptionManager (#54550)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54550

# Summary

This diff resolves a crash in RCTExceptionManager by modifying error handling. It fixes the issue by checking if `RCTJSExtraDataKey` and `RCTJSStackTraceKey` are null or not in a dictionary initializer.

Also, `RCTJSExtraDataKey` is marked as nullable but its nullability is not checked.

## Changelog:
[iOS][Fixed] - A Crash when some error information are nil

Reviewed By: javache

Differential Revision: D87140823

fbshipit-source-id: 896d41c5f6559206a6515e402d2a503df6ddb63c
This commit is contained in:
Riccardo Cipolleschi authored and meta-codesync[bot] committed 2025-11-17 08:22:19 -08:00
1 parent 8b6b47bd57
commit efd2f679f2
1 file changed
+5 -2
@@ -77,8 +77,11 @@ RCT_EXPORT_MODULE()
RCTTriggerReloadCommandListeners(@"JS Crash Reload");
} else if (!RCT_DEV) {
NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message];
NSDictionary *errorInfo =
@{NSLocalizedDescriptionKey : description, RCTJSStackTraceKey : stack, RCTJSExtraDataKey : extraDataAsJSON};
NSDictionary *errorInfo = @{
NSLocalizedDescriptionKey : description,
RCTJSStackTraceKey : stack == nil ? (id)kCFNull : stack,
RCTJSExtraDataKey : extraDataAsJSON == nil ? (id)kCFNull : extraDataAsJSON
};
RCTFatal([NSError errorWithDomain:RCTErrorDomain code:0 userInfo:errorInfo]);
}
}