Improve error when calling TM with too many args (#54691)

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

Improve error message for incorrect TurboModule invocations to avoid HostFunction: <unknown error>

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D87868433

fbshipit-source-id: f351a6e7ea59c56fcb0991eb799c4217382fdb4e
This commit is contained in:
Pieter De Baets authored and meta-codesync[bot] committed 2025-11-26 06:05:02 -08:00
1 parent 336042ccb3
commit d6c57725b7
1 file changed
+7 -1
@@ -732,13 +732,19 @@ NSInvocation *ObjCTurboModule::createMethodInvocation(
}
NSMethodSignature *methodSignature = [module methodSignatureForSelector:selector];
if (count > methodSignature.numberOfArguments - 2) {
throw jsi::JSError(
runtime,
name_ + "." + methodName + " called with too many arguments, expected up to " +
std::to_string(methodSignature.numberOfArguments - 2) + ", got " + std::to_string(count));
}
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSignature];
[inv setSelector:selector];
for (size_t i = 0; i < count; i++) {
const jsi::Value &arg = args[i];
const std::string objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2];
setInvocationArg(runtime, methodName, objCArgType, arg, i, inv, retainedObjectsForInvocation);
}