Handle fatal errors thrown by the Chrome debugger

Reviewed By: mmmulani

Differential Revision: D5219190

fbshipit-source-id: 16cff0e08de9c53d7a3e10897ddec3e6924c3bf5
This commit is contained in:
Pieter De Baets 2017-06-12 03:31:44 -07:00 committed by Facebook Github Bot
parent 947d77dab5
commit 2e4284215c
2 changed files with 19 additions and 11 deletions

View File

@ -158,10 +158,7 @@ RCT_EXPORT_MODULE()
dispatch_async(_jsQueue, ^{
if (!self.valid) {
NSError *error = [NSError errorWithDomain:@"WS" code:1 userInfo:@{
NSLocalizedDescriptionKey: @"Runtime is not ready for debugging. Make sure Packager server is running."
}];
callback(error, nil);
callback(RCTErrorWithMessage(@"Runtime is not ready for debugging. Make sure Packager server is running."), nil);
return;
}
@ -180,8 +177,13 @@ RCT_EXPORT_MODULE()
@"url": RCTNullIfNil(URL.absoluteString),
@"inject": _injectedObjects,
};
[self sendMessage:message onReply:^(NSError *error, NSDictionary<NSString *, id> *reply) {
onComplete(error);
[self sendMessage:message onReply:^(NSError *socketError, NSDictionary<NSString *, id> *reply) {
if (socketError) {
onComplete(socketError);
} else {
NSString *error = reply[@"error"];
onComplete(error ? RCTErrorWithMessage(error) : nil);
}
}];
}
@ -218,9 +220,10 @@ RCT_EXPORT_MODULE()
return;
}
NSString *result = reply[@"result"];
id objcValue = RCTJSONParse(result, NULL);
onComplete(objcValue, nil);
NSError *jsonError;
id result = RCTJSONParse(reply[@"result"], &jsonError);
NSString *error = reply[@"error"];
onComplete(result, error ? RCTErrorWithMessage(error) : jsonError);
}];
}

View File

@ -39,7 +39,7 @@ onmessage = (function() {
try {
importScripts(message.url);
} catch (err) {
error = JSON.stringify(err);
error = err.message;
}
sendReply(null /* result */, error);
},
@ -66,12 +66,17 @@ onmessage = (function() {
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], 0];
var error;
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
} else {
error = 'Failed to call function, __fbBatchedBridge is undefined';
}
} catch (err) {
error = err.message;
} finally {
sendReply(JSON.stringify(returnValue));
sendReply(JSON.stringify(returnValue), error);
}
}
};