Always fill err.message on throw

This commit is contained in:
Vitaly Puzrin 2016-12-15 02:35:12 +03:00
parent 9728a846c1
commit bd0879c1cd
3 changed files with 8 additions and 15 deletions

View file

@ -358,7 +358,7 @@ function deflate(input, options) {
deflator.push(input, true); deflator.push(input, true);
// That will never happens, if you don't cheat with options :) // That will never happens, if you don't cheat with options :)
if (deflator.err) { throw deflator.msg; } if (deflator.err) { throw deflator.msg || msg[deflator.err]; }
return deflator.result; return deflator.result;
} }

View file

@ -381,7 +381,7 @@ function inflate(input, options) {
inflator.push(input, true); inflator.push(input, true);
// That will never happens, if you don't cheat with options :) // That will never happens, if you don't cheat with options :)
if (inflator.err) { throw inflator.msg; } if (inflator.err) { throw inflator.msg || msg[inflator.err]; }
return inflator.result; return inflator.result;
} }

View file

@ -4,10 +4,11 @@
'use strict'; 'use strict';
var zlib = require('zlib'); var zlib = require('zlib');
var assert = require('assert');
var pako = require('../index'); var pako = require('../index');
var helpers = require('./helpers'); var helpers = require('./helpers');
var testInflate = helpers.testInflate; var testInflate = helpers.testInflate;
@ -170,17 +171,9 @@ describe('Inflate with dictionary', function () {
// var zCompressed = helpers.deflateSync('world', { dictionary: new Buffer('hello') }); // var zCompressed = helpers.deflateSync('world', { dictionary: new Buffer('hello') });
var zCompressed = new Buffer([ 120, 187, 6, 44, 2, 21, 43, 207, 47, 202, 73, 1, 0, 6, 166, 2, 41 ]); var zCompressed = new Buffer([ 120, 187, 6, 44, 2, 21, 43, 207, 47, 202, 73, 1, 0, 6, 166, 2, 41 ]);
try { assert.throws(function () {
pako.inflate(zCompressed, { dictionary: new Buffer('world') }); pako.inflate(zCompressed, { dictionary: new Buffer('world') });
} catch (err) { }, /data error/);
if (err.message === 'stream error') {
return;
}
throw err;
}
throw new Error('Did not throw');
}); });
it('trivial dictionary', function (done) { it('trivial dictionary', function (done) {