From c0ed6d34eca73827ce0327be42d2a0ef74e59868 Mon Sep 17 00:00:00 2001 From: Will White Date: Thu, 23 Jun 2011 13:43:05 -0400 Subject: [PATCH 1/4] Return proper "not found" error when utfgrid tables are missing. --- lib/mbtiles.js | 2 +- test/fixtures/plain_1.mbtiles | Bin 561152 -> 561152 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mbtiles.js b/lib/mbtiles.js index 7039fc5..f29ad34 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -240,8 +240,8 @@ MBTiles.prototype.grid = function(x, y, z, callback) { ); }, function(err, row, rows) { + if ((!row || !row.grid) || (err && err.errno == 1)) return callback('Grid does not exist'); if (err) return callback(err); - if (!row || !row.grid) return callback('Grid does not exist'); try { var grid = zlib.inflate( diff --git a/test/fixtures/plain_1.mbtiles b/test/fixtures/plain_1.mbtiles index 8134d91c4f62e11aee7b7f43c2705d5ed02f6b79..2ca86459d6e12d3d3a52ca2b913f612c5918a89e 100644 GIT binary patch delta 262 zcmZozpwzHHX@az18v_HA3IhW}0ub{8vDic%W1yh!BUx4;kCFK|kYwQ9SkTGL$h!F# zGrNW)qYwiNLo)+IGm{}x2h&~Vl`uH5E@g6^&J-4A2S)kHlFSh-j7J&5Cm&)828uA` zY(A-5&d35Z?7+l(sUSLh@>=~6UZ$rE%#7{~jP8t68E;MIGdRTp6v^Lw$AFUwsEARz z`K8hJmqv_oo`yU?mx=)Oy#Wfh1KFZLEC$5NKrv1rW(HzzAO^Xc3y4|TEovBnmry7y=}eg{${aI!A5-|`Ag0{SMtXdV z6K`csme&dA;|1zuWw^n>aD&mEaq46~gHtTIT Date: Tue, 28 Jun 2011 14:43:00 +0200 Subject: [PATCH 2/4] add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules From e87e8a89ab37cb2d37273ed26287f58c2791d4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 28 Jun 2011 14:43:32 +0200 Subject: [PATCH 3/4] add test mbtiles file to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3c3629e..b33eac6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +test/fixtures/non_existent.mbtiles From 537a70611f387a7dc88551d58290eb189b531462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 28 Jun 2011 23:44:44 +0200 Subject: [PATCH 4/4] don't call the callback twice in case it fails --- lib/mbtiles.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mbtiles.js b/lib/mbtiles.js index f29ad34..4b7a54f 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -253,10 +253,11 @@ MBTiles.prototype.grid = function(x, y, z, callback) { memo[r.key_name] = JSON.parse(r.key_json); return memo; }, {}); - callback(null, _(JSON.parse(grid)).extend({ data: data })); } catch (err) { - callback('Grid is invalid'); + return callback('Grid is invalid'); } + + callback(null, _(JSON.parse(grid)).extend({ data: data })); } ); };