scoundrel-remote-eval 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -46,4 +46,19 @@ describe("scoundrel - web-socket - javascript", () => {
|
|
|
46
46
|
|
|
47
47
|
expect(result).toEqual("test1, test2")
|
|
48
48
|
})
|
|
49
|
+
|
|
50
|
+
it("handles errors from method calls", async () => {
|
|
51
|
+
const stringObject = await shared.client.newObjectWithReference("Array")
|
|
52
|
+
|
|
53
|
+
let caughtError = null
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await stringObject.callMethod("nonExistentMethod")
|
|
57
|
+
} catch (error) {
|
|
58
|
+
caughtError = error
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
expect(caughtError).toBeInstanceOf(Error)
|
|
62
|
+
expect(caughtError.message).toEqual("No method called 'nonExistentMethod' on a 'Array'")
|
|
63
|
+
})
|
|
49
64
|
})
|
package/src/client/index.js
CHANGED
|
@@ -156,7 +156,9 @@ export default class Client {
|
|
|
156
156
|
return false
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
onCommand = ({command, command_id: commandID, data, ...restArgs}) => {
|
|
159
|
+
onCommand = ({command, command_id: commandID, data, error, errorStack, ...restArgs}) => {
|
|
160
|
+
logger.log(() => ["onCommand", {command, commandID, data, error, errorStack, restArgs}])
|
|
161
|
+
|
|
160
162
|
try {
|
|
161
163
|
if (!command) {
|
|
162
164
|
throw new Error(`No command key given in data: ${Object.keys(restArgs).join(", ")}`)
|
|
@@ -233,20 +235,22 @@ export default class Client {
|
|
|
233
235
|
this.respondToCommand(commandID, {response: attribute})
|
|
234
236
|
}
|
|
235
237
|
} else if (command == "command_response") {
|
|
236
|
-
if (!(commandID in this.outgoingCommands))
|
|
238
|
+
if (!(commandID in this.outgoingCommands)) {
|
|
239
|
+
throw new Error(`Outgoing command ${commandID} not found: ${Object.keys(this.outgoingCommands).join(", ")}`)
|
|
240
|
+
}
|
|
237
241
|
|
|
238
242
|
const savedCommand = this.outgoingCommands[commandID]
|
|
239
243
|
|
|
240
244
|
delete this.outgoingCommands[commandID]
|
|
241
245
|
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
246
|
+
if (error) {
|
|
247
|
+
const errorToThrow = new Error(error)
|
|
244
248
|
|
|
245
|
-
if (
|
|
246
|
-
|
|
249
|
+
if (errorStack) {
|
|
250
|
+
errorToThrow.stack = `${errorStack}\n\n${errorToThrow.stack}`
|
|
247
251
|
}
|
|
248
252
|
|
|
249
|
-
savedCommand.reject(
|
|
253
|
+
savedCommand.reject(errorToThrow)
|
|
250
254
|
} else {
|
|
251
255
|
logger.log(() => [`Resolving command ${commandID} with data`, data])
|
|
252
256
|
savedCommand.resolve(data.data)
|
|
@@ -255,9 +259,9 @@ export default class Client {
|
|
|
255
259
|
throw new Error(`Unknown command: ${command}`)
|
|
256
260
|
}
|
|
257
261
|
} catch (error) {
|
|
258
|
-
this.send({command: "command_response", command_id: commandID, error:
|
|
262
|
+
this.send({command: "command_response", command_id: commandID, error: error.message, errorStack: error.stack})
|
|
259
263
|
|
|
260
|
-
|
|
264
|
+
logger.error(error)
|
|
261
265
|
}
|
|
262
266
|
}
|
|
263
267
|
|