discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.31k stars 734 forks source link

Make JDA bubble up websocket crashes as ExceptionEvent #2647

Open DeepSnowNeeL opened 5 months ago

DeepSnowNeeL commented 5 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.22

Expected Behaviour

It should not hang on jda.awaitReady(); indefinitely when the websocket encounters an error.

In my situation I had badly updated my libraries and had in my pom this :

<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.13.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.17.0</version>
        </dependency>

This de-sync in versions caused the ListenerManager#callOnConnected from nv-websocket-client to throw java.lang.NoSuchMethodError: 'void com.fasterxml.jackson.core.util.BufferRecycler.releaseToPool()' which is not handled and reported to the end user because it seems from what I have seen that the class WebSocketClient ignores the handleCallbackError (I found out that AudioWebSocket actually does and correctly "rethrows" it by wrapping it in an ExceptionEvent)

My suggestion is that it should log the error somewhere or allow me to catch it by listening to ExceptionEvents (probably both)

(there is other methods like onUnexpectedError which might need to be handled by WebSocketClient too I guess ? maybe all others onXError, looks like onError is already implemented correctly)

Code Example for Reproduction Steps

JDA jda = JDABuilder.createDefault(token)
                    .setActivity(Activity.listening("..."))
                    .build();

            try {
                jda.awaitReady(); //hangs there
            } catch (InterruptedException e) {
                System.err.println(e);
                return;
            }

Code for JDABuilder or DefaultShardManagerBuilder used

JDA jda = JDABuilder.createDefault(token)
                    .setActivity(Activity.listening("..."))
                    .build();

Exception or Error

No error when it should be (see expected behaviour)
MinnDevelopment commented 4 months ago

This should be improved in 5.0.0-beta.24