Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-minecraft-protocol can throw an unhandled exception when the returned disconnect string is invalid. #989

Open
IceTank opened this issue Apr 16, 2022 · 1 comment

Comments

@IceTank
Copy link
Contributor

IceTank commented Apr 16, 2022

[x] The FAQ doesn't contain a resolution to my issue

Versions

  • minecraft-protocol: lastest
  • server: vanilla/spigot/paper not vanilla ?
  • node: 14

Detailed description of a problem

This line in node-minecraft-protocol can throw an unhandled error when the returned string is not a json or invalid.

const parsed = JSON.parse(message.reason)

Expected behavior

Better error handling. Maybe emit the raw string instead when the json parsing failed.

@kashalls
Copy link
Contributor

The only thing I can think of without figuring out if this is a client problem or server problem, is to do something like:

module.exports = function (client, options) {
  client.on('disconnect', message => {
    if (!message.reason) return;
    let parsed;
    try {
        parsed = JSON.parse(message.reason)
    } catch {
        debug(`Failed to parse disconnect message: ${message}`);
        return;

But the rest of this file pretty much depends on parsing the reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants