From b91d1037e5ba35a62c9b453bbb0237a7dba9f27a Mon Sep 17 00:00:00 2001 From: John Lau Date: Fri, 2 Jun 2017 17:36:20 +0900 Subject: [PATCH] Callback upon error and exception handling --- src/colour-extractor.coffee | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/colour-extractor.coffee b/src/colour-extractor.coffee index 117db46..0f1c0e3 100644 --- a/src/colour-extractor.coffee +++ b/src/colour-extractor.coffee @@ -10,8 +10,8 @@ exports.topColours = (sourceFilename, sorted, cb) -> img = gm(sourceFilename) tmpFilename = temp.path({suffix: '.miff'}) img.size((err, wh) -> - console.log err if err - + return cb(null) if err + ratio = wh.width/MAX_W w2 = wh.width/2 h2 = wh.height/2 @@ -20,7 +20,7 @@ exports.topColours = (sourceFilename, sorted, cb) -> .crop(w2, h2, w2/2, w2/2) # Center should be the most interesting .scale(Math.ceil(wh.height/ratio), MAX_W) # Scales the image, histogram generation can take some time .write('histogram:' + tmpFilename, (err) -> - console.log err if err + return cb(null) if err histogram = '' miffRS = fs.createReadStream(tmpFilename, {encoding: 'utf8'}) @@ -100,7 +100,12 @@ Example line: parseHistogramLine = (xs) -> xs = xs.trim().split(':') return null if xs.length != 2 - [+xs[0], xs[1].split('(')[1].split(')')[0].split(',').map((x) -> +x.trim())] + parsedHistogramLine = null + try + parsedHistogramLine = [+xs[0], xs[1].split('(')[1].split(')')[0].split(',').map((x) -> +x.trim())] + catch e + console.error(e, xs); + return parsedHistogramLine # Magic reduceSimilar = (xs, r) ->