From 884d3aea0a4661fbe2c0d1626790fccb26756ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 10 Apr 2017 18:26:23 +0200 Subject: [PATCH] Dont call 'next' callback twice, include error message if zip don't exit normally --- app/models/formats/ogr/shp.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/models/formats/ogr/shp.js b/app/models/formats/ogr/shp.js index 8a2a64db..0275c18c 100644 --- a/app/models/formats/ogr/shp.js +++ b/app/models/formats/ogr/shp.js @@ -59,15 +59,24 @@ ShpFormat.prototype.toSHP = function (options, callback) { var child = spawn(zip, ['-qrj', zipfile, outdirpath ]); - child.on('exit', function(code) { - //console.log("Zip complete, zip return code was " + code); - if (code) { - next(new Error("Zip command return code " + code)); - //res.statusCode = 500; - } - next(null); + var stderrData = []; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', function (data) { + stderrData.push(data); }); + child.on('exit', function(code) { + if (code !== 0) { + var errMessage = 'Zip command return code ' + code; + if (stderrData.length) { + errMessage += ', Error: ' + stderrData.join('\n'); + } + + return next(new Error(errMessage)); + } + + return next(); + }); }, function cleanupDir(topError) {