From 2294c8599c36c7e63c13f3af7449b3469159f324 Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 12 Jul 2021 15:33:35 +0530 Subject: [PATCH] Task/FORGE-1157 Error handling in R script process --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 213bc83..ce511e7 100644 --- a/index.js +++ b/index.js @@ -41,16 +41,20 @@ R.prototype.call = function(_opts, _callback) { this.options.env.input = JSON.stringify([this.d, this.path, opts]); var child = child_process.spawn("Rscript", this.args, this.options); var body = ""; - child.stderr.on("data", callback); + var error = ""; + // child.stderr.on("data", callback); child.stdout.on("data", function(d) { body += d; }); + child.stderr.on("data", (data) =>{ + error += data; + }) child.on("close", function(code) { var returnValue = body; if(isJson(body)){ returnValue = JSON.parse(body); } else { - returnValue = {'error': 'R script error'}; + returnValue = JSON.parse(error); } callback(null, returnValue); });