Skip to content

Commit

Permalink
Merge pull request #915 from miroslavLalev/query-error
Browse files Browse the repository at this point in the history
(fix/query): Row parsing could lead to uncaught errors
  • Loading branch information
sidorares committed Sep 15, 2020
2 parents 3a44ecb + afb35dc commit c2f6184
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,18 @@ class Query extends Command {
}
return this.done();
}
const row = new this._rowParser(
packet,
this._fields[this._resultIndex],
this.options,
CharsetToEncoding
);
let row;
try {
row = new this._rowParser(
packet,
this._fields[this._resultIndex],
this.options,
CharsetToEncoding
);
} catch (err) {
this._localStreamError = err;
return this.doneInsert(null);
}
if (this.onResult) {
this._rows[this._resultIndex].push(row);
} else {
Expand Down
20 changes: 20 additions & 0 deletions test/unit/commands/test-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const assert = require('assert');
const Query = require('../../../lib/commands/query');

const testError = new Error('something happened');
const testQuery = new Query({}, (err, res) => {
assert.equal(err, testError);
assert.equal(res, null);
});

testQuery._rowParser = class FailingRowParser {
constructor() {
throw testError;
}
};

testQuery.row({
isEOF: () => false
});

0 comments on commit c2f6184

Please sign in to comment.