Improve mixed geometry export error message. Closes #78

This commit is contained in:
Sandro Santilli 2013-01-11 17:09:22 +01:00
parent c84f9b1a52
commit 3e7c8f4d22
3 changed files with 26 additions and 1 deletions

View File

@ -1,5 +1,6 @@
1.3.4 (DD/MM/YY)
-----
* Improve mixed-geometry export error message (#78)
1.3.3 (11/01/13)
-----

View File

@ -551,7 +551,10 @@ console.log(['ogr2ogr',
child.on('exit', function(code) {
if ( code ) {
next(new Error("ogr2ogr returned an error (error code " + code + ")\n" + stderr));
var emsg = stderr.split('\n')[0];
// 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);
}

View File

@ -181,5 +181,26 @@ test('SHP format, unauthenticated, with utf8 data', function(done){
});
});
// See https://github.com/Vizzuality/CartoDB-SQL-API/issues/66
test('mixed type geometry', function(done){
var query = querystring.stringify({
q: "SELECT 'POINT(0 0)'::geometry as g UNION ALL "
+ "SELECT 'LINESTRING(0 0, 1 0)'::geometry",
format: 'shp'
});
assert.response(app, {
url: '/api/v1/sql?' + query,
headers: {host: 'vizzuality.cartodb.com'},
encoding: 'binary',
method: 'GET'
},{ }, function(res){
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);
done();
});
});
});