From 01f8342f9e5f81a0c9f88a2708ed9cdfe1d7543f Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Mon, 15 Jan 2018 20:30:50 -0800 Subject: [PATCH 1/3] Update autoVersion.js to emit errors instead of throwing --- src/client/autoVersion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 71f435a..f461eb0 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -11,7 +11,7 @@ module.exports = function(client, options) { debug('pinging',options.host); // TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping ping(options, function(err, response) { - if (err) throw err; // hmm + client.emit('error',err); debug('ping response',response); // TODO: could also use ping pre-connect to save description, type, max players, etc. const motd = response.description; @@ -30,7 +30,7 @@ module.exports = function(client, options) { .sort(function (a, b) { return b.version - a.version }) .concat(minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]||[]) if (versions.length === 0) { - throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); + client.emit('error',`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); } const minecraftVersion = versions[0].minecraftVersion; From c4fbd8167447fe903bd4401ed4ef548ade093592 Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Tue, 16 Jan 2018 18:24:48 -0800 Subject: [PATCH 2/3] Replaced throw for "Set encryption twice!" error with emit. --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 4e51912..05ae4c9 100644 --- a/src/client.js +++ b/src/client.js @@ -194,7 +194,7 @@ class Client extends EventEmitter setEncryption(sharedSecret) { if (this.cipher != null) - throw new Error("Set encryption twice !"); + this.emit('error','Set encryption twice!'); this.cipher = crypto.createCipheriv('aes-128-cfb8', sharedSecret, sharedSecret); this.cipher.on('error', (err) => this.emit('error', err)); this.framer.unpipe(this.socket); From 7aef44bcb7da0c8923be7619325ed23d26142e57 Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Wed, 17 Jan 2018 20:22:45 -0800 Subject: [PATCH 3/3] Emitting error objects instead of just strings. :grin: --- src/client.js | 2 +- src/client/autoVersion.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 05ae4c9..5f44cd1 100644 --- a/src/client.js +++ b/src/client.js @@ -194,7 +194,7 @@ class Client extends EventEmitter setEncryption(sharedSecret) { if (this.cipher != null) - this.emit('error','Set encryption twice!'); + this.emit('error', new Error('Set encryption twice!')); this.cipher = crypto.createCipheriv('aes-128-cfb8', sharedSecret, sharedSecret); this.cipher.on('error', (err) => this.emit('error', err)); this.framer.unpipe(this.socket); diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index f461eb0..8d61a19 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -30,7 +30,7 @@ module.exports = function(client, options) { .sort(function (a, b) { return b.version - a.version }) .concat(minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]||[]) if (versions.length === 0) { - client.emit('error',`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); + client.emit('error', new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`)); } const minecraftVersion = versions[0].minecraftVersion;