Skip to content

Commit

Permalink
Handle fatal errors thrown by the Chrome debugger
Browse files Browse the repository at this point in the history
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 2e42842
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
21 changes: 12 additions & 9 deletions Libraries/WebSocket/RCTWebSocketExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}];
}

Expand Down Expand Up @@ -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);
}];
}

Expand Down
9 changes: 7 additions & 2 deletions local-cli/server/util/debuggerWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ onmessage = (function() {
try {
importScripts(message.url);
} catch (err) {
error = JSON.stringify(err);
error = err.message;
}
sendReply(null /* result */, error);
},
Expand All @@ -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);
}
}
};
Expand Down

0 comments on commit 2e42842

Please sign in to comment.