From fdd51cfebbc9e5f3eb7e5a927b5bd8eef7604f1b Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 11 Feb 2019 14:02:01 +0100 Subject: [PATCH] fix(@embark/solidity): ensure SolidityProcess receives proper Logger instance Prior to this commit Embark had a bug where, when running `$ embark run` inside an Embark project that was freshly cloned or reset, it'd get stuck at loading the Solidity compiler. However, this only seemed to happen when Embark was used with its dashboard. When running ``` $ embark run --nodashboard ``` instead, Embark loaded Solidity successfully and moved on with compilation. This bug pretty much boiled down to `SolidityProcess` not receiving a valid `Logger` dependency when instantiated via `SolcW`. The reason this was happening is that we were sending the needed dependencies via `ProcessLauncher.send()`, which serializes/deserializes its sent data. ``` solidityProcessLauncher.send({action: 'init', options: { logger: this.logger }}); ``` And inside `SolidityProcess` ``` process.on('message', (msg) => { if (msg.action === "init") { solcProcess = new SolcProcess(msg.options); } ... } ``` `SolcProcess` passes its `logger` instance down to `longRunningProcessTimer` which uses methods on `Logger`. However, since the data had been serialized, all prototype methods on the data is gone, resulting in an error, which made Embark stop. **Why was this only a problem when using the dashboard?** Turns out we've only relied on `Logger.info()` in case the dashboard is used. --- packages/embark/src/lib/modules/solidity/solcP.js | 1 + packages/embark/src/lib/modules/solidity/solcW.js | 2 +- packages/embark/src/lib/utils/longRunningProcessTimer.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/embark/src/lib/modules/solidity/solcP.js b/packages/embark/src/lib/modules/solidity/solcP.js index 70bc9aa6c..38d048ba1 100644 --- a/packages/embark/src/lib/modules/solidity/solcP.js +++ b/packages/embark/src/lib/modules/solidity/solcP.js @@ -80,6 +80,7 @@ class SolcProcess extends ProcessWrapper { let solcProcess; process.on('message', (msg) => { if (msg.action === "init") { + msg.options.logger = console; solcProcess = new SolcProcess(msg.options); return process.send({result: "initiated"}); } diff --git a/packages/embark/src/lib/modules/solidity/solcW.js b/packages/embark/src/lib/modules/solidity/solcW.js index e9d32715b..9e8767db4 100644 --- a/packages/embark/src/lib/modules/solidity/solcW.js +++ b/packages/embark/src/lib/modules/solidity/solcW.js @@ -69,7 +69,7 @@ class SolcW { done(); }); - this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}}); + this.solcProcess.send({action: "init", options: {showSpinner: !self.useDashboard}}); if (this.ipc.isServer()) { this.ipc.on('compile', self.compile.bind(this)); diff --git a/packages/embark/src/lib/utils/longRunningProcessTimer.ts b/packages/embark/src/lib/utils/longRunningProcessTimer.ts index db5260f80..a78d7e044 100644 --- a/packages/embark/src/lib/utils/longRunningProcessTimer.ts +++ b/packages/embark/src/lib/utils/longRunningProcessTimer.ts @@ -84,7 +84,7 @@ export default class LongRunningProcessTimer { } // log our measurement and make it red if it has taken too long - if (!this.options.showSpinner && entry && strDuration && this.options && this.options.longRunningThreshold) { + if (!this.options.showSpinner && entry && strDuration !== undefined && this.options && this.options.longRunningThreshold) { if (entry.duration > this.options.longRunningThreshold) { strDuration = strDuration.red; }