Permalink
Browse files

explicitly handle errors coming out of metapng.read() in the baker

  • Loading branch information...
1 parent fb9fe9e commit 12ff6351afb175d1e07eaf0f6d00198d3618da10 @stenington stenington committed Apr 24, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/baker.js
View
16 lib/baker.js
@@ -28,10 +28,18 @@ exports.prepare = function(pnginput, data) {
*/
exports.getDataFromImage = function(pnginput) {
- var badgedata = metapng.read(pnginput, KEYWORD)
- , err = new Error('More than one `openbadges` keyword in PNG, aborting.');
+ var badgedata;
+ var err = new Error();
+ err.name = 'ParseError';
+ try{
+ badgedata = metapng.read(pnginput, KEYWORD);
+ }
+ catch (ex) {
+ err.message = 'Unable to read data from PNG: ' + ex;
+ throw err;
+ }
if (badgedata.length > 1) {
- err.name = 'ParseError';
+ err.message = 'More than one `openbadges` keyword in PNG, aborting.';
throw err;
}
return badgedata.toString('utf-8');
@@ -69,4 +77,4 @@ exports.urlFromUpload = function (file, callback) {
return callback(null, url, imagedata);
})
-};
+};

0 comments on commit 12ff635

Please sign in to comment.