Skip to content

Commit

Permalink
Attach client and source version to exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Aug 14, 2024
1 parent f5fd58a commit 205fb22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
18 changes: 18 additions & 0 deletions common/src/main/java/dev/lavalink/youtube/ClientInformation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.lavalink.youtube;

import com.sedmelluq.discord.lavaplayer.tools.exception.DetailMessageBuilder;
import dev.lavalink.youtube.clients.skeleton.Client;

public class ClientInformation extends Exception {
private ClientInformation(String message) {
super(message, null, false, false);
}

public static ClientInformation create(Client client) {
DetailMessageBuilder builder = new DetailMessageBuilder();
builder.appendField("yts.version", YoutubeSource.VERSION);
builder.appendField("client.identifier", client.getIdentifier());
builder.appendField("client.options", client.getOptions());
return new ClientInformation(builder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected AudioItem loadItemOnce(@NotNull AudioReference reference) {
throw ExceptionTools.wrapUnfriendlyExceptions("This video cannot be loaded.", Severity.SUSPICIOUS, cbl.getCause());
} catch (Throwable t) {
log.debug("Client \"{}\" threw a non-fatal exception, storing and proceeding...", client.getIdentifier(), t);
t.addSuppressed(ClientInformation.create(client));
lastException = t;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack;
import com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor;
import dev.lavalink.youtube.CannotBeLoaded;
import dev.lavalink.youtube.ClientInformation;
import dev.lavalink.youtube.UrlTools;
import dev.lavalink.youtube.UrlTools.UrlInfo;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
Expand Down Expand Up @@ -70,14 +71,18 @@ public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
try {
processWithClient(localExecutor, httpInterface, client, 0);
return; // stream played through successfully, short-circuit.
} catch (FriendlyException e) {
// usually thrown by getPlayabilityStatus when loading formats.
// these aren't considered fatal, so we just store them and continue.
lastException = e;
} catch (RuntimeException e) {
// store exception so it can be thrown if we run out of clients to
// load formats with.
e.addSuppressed(ClientInformation.create(client));
lastException = e;

if (e instanceof FriendlyException) {
// usually thrown by getPlayabilityStatus when loading formats.
// these aren't considered fatal, so we just store them and continue.
continue;
}

String message = e.getMessage();

if ("Not success status code: 403".equals(message) ||
Expand Down

0 comments on commit 205fb22

Please sign in to comment.