Skip to content

Commit dc87209

Browse files
author
Sandro Santilli
committed
Do not confuse warnings with errors on shapefile output
Closes #87
1 parent d0ab5f2 commit dc87209

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.3.6 (DD/MM/YY)
22
-----
3+
* Do not confuse warnings with errors on shapefile output (#87)
34

45
1.3.5 (19/02/13)
56
-----

app/controllers/app.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,12 @@ console.log(['ogr2ogr',
571571
//console.log('stdout: ' + data);
572572
});
573573

574-
var stderr = '';
574+
var stderr;
575+
var logErrPat = new RegExp(/^ERROR/);
575576
child.stderr.on('data', function(data) {
576-
stderr += data;
577+
data = data.toString(); // know of a faster way ?
578+
// Store only the first ERROR line
579+
if ( ! stderr && data.match(logErrPat) ) stderr = data;
577580
console.log('ogr2ogr stderr: ' + data);
578581
});
579582

test/acceptance/export/shapefile.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ test('mixed type geometry', function(done){
204204
});
205205
});
206206

207+
// See https://github.com/Vizzuality/CartoDB-SQL-API/issues/87
208+
test('errors are not confused with warnings', function(done){
209+
var query = querystring.stringify({
210+
q: "SELECT 'POINT(0 0)'::geometry as g"
211+
+ ", 1 as a_very_very_very_long_field_name"
212+
+ " UNION ALL "
213+
+ "SELECT 'LINESTRING(0 0, 1 0)'::geometry, 2",
214+
format: 'shp'
215+
});
216+
assert.response(app, {
217+
url: '/api/v1/sql?' + query,
218+
headers: {host: 'vizzuality.cartodb.com'},
219+
encoding: 'binary',
220+
method: 'GET'
221+
},{ }, function(res){
222+
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
223+
assert.deepEqual(res.headers['content-disposition'], 'inline');
224+
assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body);
225+
var parsedBody = JSON.parse(res.body);
226+
var expectedBody = {"error":["ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile."]}
227+
assert.deepEqual(parsedBody, expectedBody);
228+
done();
229+
});
230+
});
231+
207232
test('skipfields controls fields included in SHP output', function(done){
208233
var query = querystring.stringify({
209234
q: "SELECT 111 as skipme, 222 as keepme, 'POINT(0 0)'::geometry as g",

0 commit comments

Comments
 (0)