Retur a proper error message when ogr2ogr command fails
This commit is contained in:
parent
d60e2107af
commit
6dba06130b
@ -173,34 +173,25 @@ OgrFormat.prototype.toOGR = function(options, out_format, out_filename, callback
|
||||
next(err);
|
||||
});
|
||||
|
||||
var stdout = '';
|
||||
child.stdout.on('data', function(data) {
|
||||
stdout += data;
|
||||
//console.log('stdout: ' + data);
|
||||
});
|
||||
|
||||
var stderr;
|
||||
var logErrPat = new RegExp(/^ERROR/);
|
||||
child.stderr.on('data', function(data) {
|
||||
data = data.toString(); // know of a faster way ?
|
||||
// Store only the first ERROR line
|
||||
if ( ! stderr && data.match(logErrPat) ) {
|
||||
stderr = data;
|
||||
}
|
||||
console.log('ogr2ogr stderr: ' + data);
|
||||
var stderrData = [];
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stderr.on('data', function (data) {
|
||||
stderrData.push(data);
|
||||
});
|
||||
|
||||
child.on('exit', function(code) {
|
||||
if ( code ) {
|
||||
console.log("ogr2ogr exited with code " + code);
|
||||
var emsg = stderr ? stderr.split('\n')[0] : ( "unknown ogr2ogr error (code " + code + ")" );
|
||||
// TODO: add more info about this error ?
|
||||
//if ( RegExp(/attempt to write non-.*geometry.*to.*type shapefile/i).exec(emsg) )
|
||||
next(new Error(emsg));
|
||||
} else {
|
||||
next(null);
|
||||
if (code !== 0) {
|
||||
var errMessage = 'ogr2ogr command return code ' + code;
|
||||
if (stderrData.length > 0) {
|
||||
errMessage += ', Error: ' + stderrData.join('\n');
|
||||
}
|
||||
|
||||
return next(new Error(errMessage));
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
|
||||
},
|
||||
function finish(err) {
|
||||
callback(err, out_filename);
|
||||
|
@ -197,8 +197,9 @@ it('mixed type geometry', function(done){
|
||||
assert.deepEqual(res.headers['content-disposition'], 'inline');
|
||||
assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
var expectedBody = {"error":["ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile."]};
|
||||
assert.deepEqual(parsedBody, expectedBody);
|
||||
var error = parsedBody.error[0];
|
||||
var expectedError = /Attempt to write non-point \(LINESTRING\) geometry to point shapefile/g;
|
||||
assert.ok(expectedError.test(error), error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -222,8 +223,9 @@ it('errors are not confused with warnings', function(done){
|
||||
assert.deepEqual(res.headers['content-disposition'], 'inline');
|
||||
assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
var expectedBody = {"error":["ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile."]};
|
||||
assert.deepEqual(parsedBody, expectedBody);
|
||||
var error = parsedBody.error[0];
|
||||
var expectedError = /Attempt to write non-point \(LINESTRING\) geometry to point shapefile/g;
|
||||
assert.ok(expectedError.test(error), error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user