Skip to content

Commit da2e62c

Browse files
authored
fix(Chakra): Throw less cryptic error message for invalid bundle (microsoft#762)
Currently, when a bundle has not been created properly using the `react-native bundle` command, an exception along the lines of 'Argument can not be null' is thrown. Now we have a more specific error message along the lines of "Cannot resolve '__fbBatchedBridge' ...". Fixes microsoft#719
1 parent e5670ae commit da2e62c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ReactWindows/ReactNative/Chakra/Executor/ChakraJavaScriptExecutor.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ private JavaScriptValue EnsureParseFunction()
402402
return _parseFunction;
403403
}
404404

405+
private JavaScriptValue EnsureBatchedBridge()
406+
{
407+
var globalObject = EnsureGlobalObject();
408+
var propertyId = JavaScriptPropertyId.FromString(FBBatchedBridgeVariableName);
409+
var fbBatchedBridge = globalObject.GetProperty(propertyId);
410+
if (fbBatchedBridge.ValueType != JavaScriptValueType.Object)
411+
{
412+
throw new InvalidOperationException(
413+
Invariant($"Could not resolve '{FBBatchedBridgeVariableName}' object. Check the JavaScript bundle to ensure it is generated correctly."));
414+
}
415+
416+
return fbBatchedBridge;
417+
}
418+
405419
private JavaScriptValue EnsureStringifyFunction()
406420
{
407421
if (!_stringifyFunction.IsValid)
@@ -418,9 +432,7 @@ private JavaScriptValue EnsureCallFunction()
418432
{
419433
if (!_callFunctionAndReturnFlushedQueueFunction.IsValid)
420434
{
421-
var globalObject = EnsureGlobalObject();
422-
var propertyId = JavaScriptPropertyId.FromString(FBBatchedBridgeVariableName);
423-
var fbBatchedBridge = globalObject.GetProperty(propertyId);
435+
var fbBatchedBridge = EnsureBatchedBridge();
424436
var functionPropertyId = JavaScriptPropertyId.FromString("callFunctionReturnFlushedQueue");
425437
_callFunctionAndReturnFlushedQueueFunction = fbBatchedBridge.GetProperty(functionPropertyId);
426438
}
@@ -432,9 +444,7 @@ private JavaScriptValue EnsureInvokeFunction()
432444
{
433445
if (!_invokeCallbackAndReturnFlushedQueueFunction.IsValid)
434446
{
435-
var globalObject = EnsureGlobalObject();
436-
var propertyId = JavaScriptPropertyId.FromString(FBBatchedBridgeVariableName);
437-
var fbBatchedBridge = globalObject.GetProperty(propertyId);
447+
var fbBatchedBridge = EnsureBatchedBridge();
438448
var functionPropertyId = JavaScriptPropertyId.FromString("invokeCallbackAndReturnFlushedQueue");
439449
_invokeCallbackAndReturnFlushedQueueFunction = fbBatchedBridge.GetProperty(functionPropertyId);
440450
}
@@ -446,9 +456,7 @@ private JavaScriptValue EnsureFlushedQueueFunction()
446456
{
447457
if (!_flushedQueueFunction.IsValid)
448458
{
449-
var globalObject = EnsureGlobalObject();
450-
var propertyId = JavaScriptPropertyId.FromString(FBBatchedBridgeVariableName);
451-
var fbBatchedBridge = globalObject.GetProperty(propertyId);
459+
var fbBatchedBridge = EnsureBatchedBridge();
452460
var functionPropertyId = JavaScriptPropertyId.FromString("flushedQueue");
453461
_flushedQueueFunction = fbBatchedBridge.GetProperty(functionPropertyId);
454462
}

0 commit comments

Comments
 (0)