Permalink
Browse files

Handle fatal errors thrown by the Chrome debugger

Reviewed By: mmmulani

Differential Revision: D5219190

fbshipit-source-id: 16cff0e08de9c53d7a3e10897ddec3e6924c3bf5
  • Loading branch information...
javache authored and facebook-github-bot committed Jun 12, 2017
1 parent 947d77d commit 2e4284215c5482f3e0f4b9fba0046661aa9cd992
Showing with 19 additions and 11 deletions.
  1. +12 −9 Libraries/WebSocket/RCTWebSocketExecutor.m
  2. +7 −2 local-cli/server/util/debuggerWorker.js
@@ -158,10 +158,7 @@ - (void)sendMessage:(NSDictionary<NSString *, id> *)message onReply:(RCTWSMessag
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 @@ - (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)URL onCompl
@"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 @@ - (void)_executeJSCall:(NSString *)method arguments:(NSArray *)arguments callbac
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);
}];
}
@@ -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);
}
}
};

0 comments on commit 2e42842

Please sign in to comment.