fix(iOS): provide useful error message about dependency provider (#49843)

Summary:
Currently, when integrating into a native app using ReactNativeFactory, when we forget to set `dependencyProvider` we get a random crash exception instructing us (depending on native modules in our app) about an unrecognized selector:

![CleanShot 2025-03-05 at 15 21 53@2x](https://github.com/user-attachments/assets/04b8d4fe-1e40-4023-af1b-1825a3a99f33)

After this change we get a proper error informing us that we for got to set dependencyProvider:

![CleanShot 2025-03-05 at 15 22 16@2x](https://github.com/user-attachments/assets/39bb1c2a-3efc-4689-a92e-ca2ee54cb6a4)

## Changelog:

[IOS] [ADDED] - Useful error message about setting dependency provider

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

Test Plan: CI Green

Reviewed By: cortinico

Differential Revision: D70631515

Pulled By: cipolleschi

fbshipit-source-id: d99c8fa12fdb0624a01fe16c50fe0f2d10554f94
This commit is contained in:
Oskar Kwaśniewski authored and Facebook GitHub Bot committed 2025-03-10 12:09:52 -07:00
1 parent 22cd3b1023
commit e1464c0975
1 file changed
+7
@@ -196,6 +196,13 @@ using namespace facebook::react;
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
#if USE_OSS_CODEGEN
if (self.delegate.dependencyProvider == nil) {
[NSException raise:@"ReactNativeFactoryDelegate dependencyProvider is nil"
format:@"Delegate must provide a valid dependencyProvider"];
}
#endif
return RCTAppSetupDefaultModuleFromClass(moduleClass, self.delegate.dependencyProvider);
}