mapbox/mapnik-omnivore — pull request #32 by yhahn (2014-09-09 04:30:23+00:00)
Title: Reduce scope of try/catch blocks

Moves code that doesn't need catching out of `try/catch` blocks. In particular calling a passed callback within a `try` block can have unintended consequences:

// callback someone else passes to our API.
// it has a bad call to undefinedFunction(), leading to an exception.
function done(err, data) {
if (err) return console.warn(err);
undefinedFunction();
}

function mymodule(options, callback) {
try {
// this code is good and will not throw
var data = 5 + 5;
// but the callback itself may throw, and isn't our code!
callback(null, data);
} catch(err) {
callback(new Error('error occurred!'));
}
}

> mymodule({}, done);
[Error: error occurred!]

The gist: if callback is wrapped by `try` you'll potentially end up catching other people's errors too and masking them making it look like an error occurred in `mapnik-omnivore` when it's really in the API caller's code.