Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJS-193] wrong error returned "Cannot read properties of undefined…
… (reading 'charset')" when wrong handshake
  • Loading branch information
rusher committed Apr 25, 2022
1 parent 2ae57a9 commit 5121d6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/config/connection-options.js
Expand Up @@ -48,7 +48,7 @@ class ConnectionOptions {
this.collation = Collations.fromName(opts.collation.toUpperCase());
if (this.collation === undefined) throw new RangeError("Unknown collation '" + opts.collation + "'");
} else {
this.collation = Collations.fromIndex(opts.charsetNumber);
this.collation = opts.charsetNumber ? Collations.fromIndex(opts.charsetNumber) : undefined;
}

// connection options
Expand Down
4 changes: 3 additions & 1 deletion lib/connection.js
Expand Up @@ -591,7 +591,9 @@ class Connection extends EventEmitter {
handshake.once(
'end',
function () {
if (!this.opts.collation) {
// this.info.collation might not be initialized
// in case of handshake throwing error
if (!this.opts.collation && this.info.collation) {
this.opts.emit('collation', this.info.collation);
}

Expand Down

0 comments on commit 5121d6c

Please sign in to comment.