From 1bace4abb661d5b68a73f8afa257a14cbb7edb69 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 May 2013 20:00:44 +0800 Subject: [PATCH] Improve error reporting in RPC by printing stack trace. --- browser/atom/rpc_server.coffee | 22 +++++++++++++--------- renderer/api/lib/remote.coffee | 4 +++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index 9c222b36f58..6866542109f 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -33,6 +33,10 @@ valueToMeta = (processId, routingId, value) -> meta +# Convert Error into meta data. +errorToMeta = (error) -> + type: 'error', message: error.message, stack: (error.stack || error) + # Convert array of meta data from renderer into array of real values. unwrapArgs = (processId, routingId, args) -> args.map (meta) -> @@ -51,13 +55,13 @@ ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) -> try event.result = valueToMeta processId, routingId, require(module) catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) -> try event.result = valueToMeta processId, routingId, global[name] catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (event, processId, routingId) -> objectsRegistry.clear processId, routingId @@ -70,7 +74,7 @@ ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) -> window.getRoutingId() == routingId event.result = valueToMeta processId, routingId, window catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) -> try @@ -81,7 +85,7 @@ ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) -> obj = new (Function::bind.apply(constructor, [null].concat(args))) event.result = valueToMeta processId, routingId, obj catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> try @@ -90,7 +94,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> ret = func.apply global, args event.result = valueToMeta processId, routingId, ret catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) -> try @@ -99,28 +103,28 @@ ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, arg ret = obj[method].apply(obj, args) event.result = valueToMeta processId, routingId, ret catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_MEMBER_SET', (event, processId, routingId, id, name, value) -> try obj = objectsRegistry.get id obj[name] = value catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, processId, routingId, id, name) -> try obj = objectsRegistry.get id event.result = valueToMeta processId, routingId, obj[name] catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_REFERENCE', (event, processId, routingId, id) -> try obj = objectsRegistry.get id event.result = valueToMeta processId, routingId, obj catch e - event.result = type: 'error', value: e.message + event.result = errorToMeta e ipc.on 'ATOM_BROWSER_DEREFERENCE', (processId, routingId, storeId) -> objectsRegistry.remove processId, routingId, storeId diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 74e3fdc9e1b..134360b404b 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -18,9 +18,11 @@ wrapArgs = (args) -> # Convert meta data from browser into real value. metaToValue = (meta) -> switch meta.type - when 'error' then throw new Error(meta.value) when 'value' then meta.value when 'array' then (metaToValue(el) for el in meta.members) + when 'error' + console.log meta.stack + throw new Error(meta.message) else if meta.type is 'function' # A shadow class to represent the remote function object.