diff --git a/packages/core/code-runner/src/index.ts b/packages/core/code-runner/src/index.ts index a28c86454..783360ebe 100644 --- a/packages/core/code-runner/src/index.ts +++ b/packages/core/code-runner/src/index.ts @@ -52,7 +52,7 @@ class CodeRunner { this.vm.registerVar(varName, code, cb); } - private evalCode(code: string, cb: Callback, tolerateError = false) { + private evalCode(code: string, cb: Callback, tolerateError = false, logCode = true, logError = true) { cb = cb || (() => { }); if (!code) { @@ -61,8 +61,12 @@ class CodeRunner { this.vm.doEval(code, tolerateError, (err, result) => { if (err) { - this.logger.error(__("Error running code: %s", code)); - this.logger.error(err.toString()); + if (logCode) { + this.logger.error(__("Error running code: %s", code)); + } + if (logError) { + this.logger.error(err.toString()); + } return cb(err); } diff --git a/packages/core/console/src/lib/index.ts b/packages/core/console/src/lib/index.ts index 93c2240c0..57fdc8d08 100644 --- a/packages/core/console/src/lib/index.ts +++ b/packages/core/console/src/lib/index.ts @@ -47,13 +47,18 @@ class Console { if (this.ipc.isServer()) { this.ipc.on("console:executeCmd", (cmd: string, cb: any) => { - this.executeCmd(cmd, (err: string, result: any) => { - let error = null; + this.executeCmd(cmd, (err: any, result: any) => { if (err) { // reformat for IPC reply - error = { name: "Console error", message: err, stack: err }; + err = { name: "Console error", message: err, stack: err.stack }; + return cb(err); } - cb(error, util.inspect(result)); + cb(null, util.inspect(result)); + }); + }); + this.ipc.on("console:executePartial", (cmd: string, cb: any) => { + this.executePartial(cmd, (_: any, result: any) => { + cb(null, util.inspect(result)); }); }); this.ipc.on("console:history:save", true, (cmd: string) => { @@ -70,6 +75,7 @@ class Console { if (cb) { cb(); } }); this.events.setCommandHandler("console:executeCmd", this.executeCmd.bind(this)); + this.events.setCommandHandler("console:executePartial", this.executePartial.bind(this)); this.events.setCommandHandler("console:history", (cb: any) => this.getHistory(this.cmdHistorySize(), cb)); this.registerConsoleCommands(); @@ -149,7 +155,19 @@ class Console { return false; } - private executeCmd(cmd: string, callback: any) { + private executePartial(cmd: string, callback: any) { + // if this is the embark console process, send the command to the process + // running all the needed services (ie the process running `embark run`) + if (this.isEmbarkConsole) { + return this.ipc.request("console:executePartial", cmd, callback); + } + + this.executeCmd(cmd, (_: any, result: any) => { + callback(null, result); + }); + } + + private executeCmd(cmd: string, callback?: any, logEvalCode = false, logEvalError = false) { // if this is the embark console process, send the command to the process // running all the needed services (ie the process running `embark run`) if (this.isEmbarkConsole) { @@ -197,12 +215,7 @@ class Console { return callback(null, output); } - this.events.request("runcode:eval", cmd, (err: Error, result: any) => { - if (err) { - return callback(err.message); - } - callback(null, result); - }, true); + this.events.request("runcode:eval", cmd, callback, true, logEvalCode, logEvalError); } private registerConsoleCommands() { diff --git a/packages/embark/src/cmd/dashboard/repl.js b/packages/embark/src/cmd/dashboard/repl.js index ae9b88937..6b89ec2c8 100644 --- a/packages/embark/src/cmd/dashboard/repl.js +++ b/packages/embark/src/cmd/dashboard/repl.js @@ -27,7 +27,7 @@ class REPL { this.events.request('console:executeCmd', cmd.trim(), function (err, message) { if (err) { // Do not return as the first param (error), because the dashboard doesn't print errors - return callback(null, err.red); + return callback(null, err.message ? err.message.red : err.red); } callback(null, message === undefined ? '' : message); // This way, we don't print undefined }); @@ -58,9 +58,9 @@ class REPL { hint = partial; } - this.events.request('console:executeCmd', context, (err, result) => { - if (err !== null) { - cb(err, [[], partial]); + this.events.request('console:executePartial', context, (err, result) => { + if (err || !result) { + return cb(null, [[], partial]); } let props = Object