Improve error reporting in RPC by printing stack trace.

This commit is contained in:
Cheng Zhao 2013-05-14 20:00:44 +08:00
parent d8a6c68bf9
commit 1bace4abb6
2 changed files with 16 additions and 10 deletions

View file

@ -33,6 +33,10 @@ valueToMeta = (processId, routingId, value) ->
meta 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. # Convert array of meta data from renderer into array of real values.
unwrapArgs = (processId, routingId, args) -> unwrapArgs = (processId, routingId, args) ->
args.map (meta) -> args.map (meta) ->
@ -51,13 +55,13 @@ ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
try try
event.result = valueToMeta processId, routingId, require(module) event.result = valueToMeta processId, routingId, require(module)
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) -> ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) ->
try try
event.result = valueToMeta processId, routingId, global[name] event.result = valueToMeta processId, routingId, global[name]
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (event, processId, routingId) -> ipc.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (event, processId, routingId) ->
objectsRegistry.clear processId, routingId objectsRegistry.clear processId, routingId
@ -70,7 +74,7 @@ ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) ->
window.getRoutingId() == routingId window.getRoutingId() == routingId
event.result = valueToMeta processId, routingId, window event.result = valueToMeta processId, routingId, window
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) -> ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) ->
try try
@ -81,7 +85,7 @@ ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) ->
obj = new (Function::bind.apply(constructor, [null].concat(args))) obj = new (Function::bind.apply(constructor, [null].concat(args)))
event.result = valueToMeta processId, routingId, obj event.result = valueToMeta processId, routingId, obj
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) ->
try try
@ -90,7 +94,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) ->
ret = func.apply global, args ret = func.apply global, args
event.result = valueToMeta processId, routingId, ret event.result = valueToMeta processId, routingId, ret
catch e 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) -> ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) ->
try try
@ -99,28 +103,28 @@ ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, arg
ret = obj[method].apply(obj, args) ret = obj[method].apply(obj, args)
event.result = valueToMeta processId, routingId, ret event.result = valueToMeta processId, routingId, ret
catch e 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) -> ipc.on 'ATOM_BROWSER_MEMBER_SET', (event, processId, routingId, id, name, value) ->
try try
obj = objectsRegistry.get id obj = objectsRegistry.get id
obj[name] = value obj[name] = value
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, processId, routingId, id, name) -> ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, processId, routingId, id, name) ->
try try
obj = objectsRegistry.get id obj = objectsRegistry.get id
event.result = valueToMeta processId, routingId, obj[name] event.result = valueToMeta processId, routingId, obj[name]
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_REFERENCE', (event, processId, routingId, id) -> ipc.on 'ATOM_BROWSER_REFERENCE', (event, processId, routingId, id) ->
try try
obj = objectsRegistry.get id obj = objectsRegistry.get id
event.result = valueToMeta processId, routingId, obj event.result = valueToMeta processId, routingId, obj
catch e catch e
event.result = type: 'error', value: e.message event.result = errorToMeta e
ipc.on 'ATOM_BROWSER_DEREFERENCE', (processId, routingId, storeId) -> ipc.on 'ATOM_BROWSER_DEREFERENCE', (processId, routingId, storeId) ->
objectsRegistry.remove processId, routingId, storeId objectsRegistry.remove processId, routingId, storeId

View file

@ -18,9 +18,11 @@ wrapArgs = (args) ->
# Convert meta data from browser into real value. # Convert meta data from browser into real value.
metaToValue = (meta) -> metaToValue = (meta) ->
switch meta.type switch meta.type
when 'error' then throw new Error(meta.value)
when 'value' then meta.value when 'value' then meta.value
when 'array' then (metaToValue(el) for el in meta.members) when 'array' then (metaToValue(el) for el in meta.members)
when 'error'
console.log meta.stack
throw new Error(meta.message)
else else
if meta.type is 'function' if meta.type is 'function'
# A shadow class to represent the remote function object. # A shadow class to represent the remote function object.