Skip to content

Commit 299b67e

Browse files
author
ionut.stan
committed
The Worker and ElectronIPC routers now set incomingRequest.stackInErrorMessage to true automatically and by default.
1 parent b0ae86d commit 299b67e

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jsonrpc-bidirectional",
33
"description": "Bidirectional JSONRPC over web sockets or HTTP with extensive plugin support.",
4-
"version": "6.7.1",
4+
"version": "6.7.2",
55
"scripts": {
66
"build": "node build.js",
77
"test": "node --expose-gc --max-old-space-size=1024 tests/main.js",

src/BidirectionalElectronIPC.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
145145

146146
const nConnectionID = ++this._nConnectionIDCounter;
147147

148-
const strChannel = "jsonrpc_winid_" + (window || self).require("electron").remote.getCurrentWindow().id;
148+
const strChannel = "jsonrpc_winid_" + (window || self).require("electron").remote.getCurrentWindow().id; // eslint-disable-line
149149

150150
const objSession = {
151151
browserWindow: null,
@@ -158,7 +158,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
158158

159159
this._objSessions[nConnectionID] = objSession;
160160

161-
(window || self).require("electron").ipcRenderer.on(
161+
(window || self).require("electron").ipcRenderer.on( // eslint-disable-line
162162
strChannel,
163163
async (event, objJSONRPCRequest) => {
164164
await this._routeMessage(objJSONRPCRequest, objSession, strChannel);
@@ -279,7 +279,8 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
279279

280280
incomingRequest.connectionID = nConnectionID;
281281
incomingRequest.router = this;
282-
282+
283+
incomingRequest.stackInErrorMessage = true;
283284

284285
try
285286
{
@@ -312,7 +313,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
312313
}
313314
else
314315
{
315-
(window || self).require("electron").ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized);
316+
(window || self).require("electron").ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized); // eslint-disable-line
316317
}
317318
}
318319
}

src/BidirectionalWorkerRouter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ let cluster = require("cluster");
44
if(!cluster)
55
{
66
cluster = {
7-
isMaster: !(self && self.document === undefined),
8-
isWorker: !!(self && self.document === undefined)
7+
isMaster: !(self && self.document === undefined), // eslint-disable-line
8+
isWorker: !!(self && self.document === undefined) // eslint-disable-line
99
};
1010
}
1111

@@ -81,7 +81,7 @@ class BidirectionalWorkerRouter extends JSONRPC.RouterBase
8181
strEndpointPath = JSONRPC.EndpointBase.normalizePath(strEndpointPath);
8282
}
8383

84-
assert(cluster.isMaster || process === worker || self === worker, "Unknown worker type.");
84+
assert(cluster.isMaster || process === worker || self === worker, "Unknown worker type."); // eslint-disable-line
8585

8686

8787
const nConnectionID = ++this._nConnectionIDCounter;
@@ -318,6 +318,7 @@ class BidirectionalWorkerRouter extends JSONRPC.RouterBase
318318
incomingRequest.connectionID = nConnectionID;
319319
incomingRequest.router = this;
320320

321+
incomingRequest.stackInErrorMessage = true;
321322

322323
try
323324
{

src/IncomingRequest.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class IncomingRequest
4141
//this._webSocket
4242
//this._httpRequest
4343

44+
// Only change this to true if it is safe to export stack traces to the RPC called.
45+
this._bStackInErrorMessage = false;
46+
4447
Object.seal(this);
4548
}
4649

@@ -317,6 +320,27 @@ class IncomingRequest
317320
}
318321

319322

323+
/**
324+
* Consulted when serializing the response.
325+
* Determines if the stack trace will be appended to the error message, in case of returning an error.
326+
*
327+
* @returns {boolean}
328+
*/
329+
get stackInErrorMessage()
330+
{
331+
return this._bStackInErrorMessage;
332+
}
333+
334+
335+
/**
336+
* @param {boolean} bAllow
337+
*/
338+
set stackInErrorMessage(bAllow)
339+
{
340+
this._bStackInErrorMessage = bAllow;
341+
}
342+
343+
320344
/**
321345
* @param {string|Buffer|Object} mxResultSerialized
322346
*/
@@ -576,7 +600,7 @@ class IncomingRequest
576600
if(this.callResult instanceof Error)
577601
{
578602
objResponse.error = {
579-
message: this.callResult.message,
603+
message: this.callResult.message + (this.stackInErrorMessage ? " " + this.callResult.stack : ""),
580604
code: (this.callResult instanceof JSONRPC.Exception) ? this.callResult.code : 0,
581605
data: this.callResult.stack.split(/[\r\n]+/mg)
582606
};

0 commit comments

Comments
 (0)