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

Bug(FILE.EXTENSION): SyntaxError: Unexpected end of JSON input #105

Closed
4 tasks done
RonaldZav opened this issue Apr 28, 2024 · 6 comments
Closed
4 tasks done

Bug(FILE.EXTENSION): SyntaxError: Unexpected end of JSON input #105

RonaldZav opened this issue Apr 28, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@RonaldZav
Copy link

RonaldZav commented Apr 28, 2024

Description of the problem

When using the play command, the messages are sent but the music does not start playing and these errors appear:

Excuse me if it is an error in my code.

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at MoonlinkNode.message (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Entities\MoonlinkNode.js:139:28)
    at MoonlinkWebSocket.emit (node:events:517:28)
    at Socket.<anonymous> (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Services\MoonlinkWebSocket.js:120:34)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9)
    at Readable.push (node:internal/streams/readable:278:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) Promise {
  <rejected> SyntaxError: Unexpected end of JSON input
      at JSON.parse (<anonymous>)
      at MoonlinkNode.message (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Entities\MoonlinkNode.js:139:28)
      at MoonlinkWebSocket.emit (node:events:517:28)
      at Socket.<anonymous> (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Services\MoonlinkWebSocket.js:120:34)
      at Socket.emit (node:events:517:28)
      at addChunk (node:internal/streams/readable:368:12)
      at readableAddChunk (node:internal/streams/readable:341:9)
      at Readable.push (node:internal/streams/readable:278:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
}
Emitted data that has not been implemented; opcode: 10
Emitted data that has not been implemented; opcode: 4
Emitted data that has not been implemented; opcode: 10

Step by Step

I'm running this command:

const { EmbedBuilder, ApplicationCommandOptionType } = require("discord.js")

module.exports = {
    name: "play",
    description: "Write a song.",
	options: [
		{
			name: "search",
            description: "Select an member.",
            type: ApplicationCommandOptionType.String,
            required: true
		},
	],
		
		
    run: async (client, interaction, lang) => {
        let query = interaction.options.getString("search");

    if (!interaction.member.voice.channel) {
        // Responding with a message if the user is not in a voice channel
        return interaction.reply({
            content: `You are not in a voice channel`,
            ephemeral: true
        });
    }

    let player = client.moon.players.create({
        guildId: interaction.guild.id,
        voiceChannel: interaction.member.voice.channel.id,
        textChannel: interaction.channel.id,
        autoPlay: true
    });

    if (!player.connected) {
        player.connect({
            setDeaf: true,
            setMute: false
        });
    }

    let res = await client.moon.search({
        query,
        source: "youtube",
        requester: interaction.user.id
    });

    if (res.loadType === "loadfailed") {
        return interaction.reply({
            content: `:x: Load failed - the system is not cooperating.`
        });
    } else if (res.loadType === "empty") {
        return interaction.reply({
            content: `:x: No matches found!`
        });
    }

    const embed = new EmbedBuilder()
    .setDescription(lang.embeds.song_added_to_queue.content.description.replace(/<musicname>/, res.tracks[0].title).replace(/<musicurl>/, res.tracks[0].url))
    .setThumbnail(res.tracks[0].artworkUrl)
    .setColor("#ffc200")

    if (res.loadType === "playlist") {
        interaction.reply({
            content: `${res.playlistInfo.name} This playlist has been added to the waiting list, spreading joy`
        });

        for (const track of res.tracks) {
            // Adding tracks to the queue if it's a playlist
            player.queue.add(track);
        }
    } else {
        player.queue.add(res.tracks[0]);
        interaction.reply({
            embeds: [embed]
        });
    }

    if (!player.playing) {
        player.play();
    }

}}

and this returns:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at MoonlinkNode.message (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Entities\MoonlinkNode.js:139:28)
    at MoonlinkWebSocket.emit (node:events:517:28)
    at Socket.<anonymous> (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Services\MoonlinkWebSocket.js:120:34)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9)
    at Readable.push (node:internal/streams/readable:278:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) Promise {
  <rejected> SyntaxError: Unexpected end of JSON input
      at JSON.parse (<anonymous>)
      at MoonlinkNode.message (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Entities\MoonlinkNode.js:139:28)
      at MoonlinkWebSocket.emit (node:events:517:28)
      at Socket.<anonymous> (C:\Users\ronal\Documents\GitHub\mahiro\node_modules\moonlink.js\dist\src\@Services\MoonlinkWebSocket.js:120:34)
      at Socket.emit (node:events:517:28)
      at addChunk (node:internal/streams/readable:368:12)
      at readableAddChunk (node:internal/streams/readable:341:9)
      at Readable.push (node:internal/streams/readable:278:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
}
Emitted data that has not been implemented; opcode: 10
Emitted data that has not been implemented; opcode: 4
Emitted data that has not been implemented; opcode: 10

Package Version

3.6.4

First of all, please confirm:

  • Have you checked if there isn't already another issue with the same problem either on GitHub or on the Discord server?
  • Have you checked if there hasn't been a recent commit fixing this problem?
  • Are you using the latest version?
  • I agree to behave and wait patiently
@RonaldZav RonaldZav added the bug Something isn't working label Apr 28, 2024
@1Lucas1apk
Copy link
Member

I'm going to replace the internal socket module with ws, I think it can fix your error

@Zendrex
Copy link

Zendrex commented May 1, 2024

Thought that I would mention that since v3.6.6...v3.6.8 has moved over to the ws module, moonlink now works** with bun after patching MoonlinkMakeRequest.ts to utilize bun's fetch rather utilizing http/http2/https/zlib.

The (Bun Specific) Patch: https://gist.github.com/Zendrex/43624347a198487b8fb361065264c044

At this point in time, I spent all of 5 minutes doing this just to test simple functionality.

@ThePedroo
Copy link
Contributor

Worth mentioning that globalThis.fetch from neither Bun nor Node.js has HTTP/2, so it cannot really be replaced with it

Also, Bun does have fine https/http support, however when it comes to decompression it doesn't, but only NodeLink by default has compression enabled

Also with the change to ws it works as it utilizes uWebSocket, not ws.

@Zendrex
Copy link

Zendrex commented May 1, 2024

Also, Bun does have fine https/http support, however when it comes to decompression it doesn't, but only NodeLink by default has compression enabled

This is true, and the patch I put above was 100% a lazy hack to get it working strictly with the latest version of bun at time of writing which is 1.1.6. The reason being is that moonlink actually fails with the current implementation in MoonlinkMakeRequest due to zlib.createBrotliDecompress() not being implemented as referenced in oven-sh/bun#267

I haven't tested with earlier version myself but from what I've read, it may be resolved by downgrading to 1.1.3 as referenced in oven-sh/bun#7248

Also with the change to ws it works as it utilizes uWebSocket, not ws.

I shoulda clarified further, but yes this is the case.

Edit: To clarify, I'm not suggesting that any changes are made to moonlink as of right now since the lack of HTTP/2 support, however for my use case, it does the job.

@ThePedroo
Copy link
Contributor

Oh, right. Although Lucas could easily implement those by checking if process.isBun === true, not affecting Node.js moonlink

@1Lucas1apk
Copy link
Member

I don't plan to make this change in v3 of moonlink, this will be in the rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants