refactor(LogHandler): use the exception itself instead of a string for buildSentryErrorMessage

This commit is contained in:
anthorob committed 2024-07-14 00:12:14 -04:00
1 parent aba0441021
commit 0db751af44
4 files changed
+5 -5

No files matched your search

@@ -79,7 +79,7 @@ public class LogHandler {
private static void tryGracefulSlashContextError(CommandException exception, CommandContext context) { private static void tryGracefulSlashContextError(CommandException exception, CommandContext context) {
if (context instanceof SlashCommandContext slashCommandContext) { if (context instanceof SlashCommandContext slashCommandContext) {
slashCommandContext.reply(MessageFunction.buildSentryErrorMessage(exception.getMessage())); slashCommandContext.reply(MessageFunction.buildSentryErrorMessage(exception));
} }
} }
} }
@@ -124,6 +124,6 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
LogHandler.log(e); LogHandler.log(e);
if (!silent) if (!silent)
context.replyToMessage(MessageFunction.buildSentryErrorMessage("Failed to load track: " + e.getMessage())); context.replyToMessage(MessageFunction.buildSentryErrorMessage(new RuntimeException("Failed to load track: " + e.getMessage())));
} }
} }
@@ -118,7 +118,7 @@ public class TrackScheduler extends AudioEventAdapter {
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) { public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
logger.debug("Guild {}: exception while playing track [{}]: {}", guild.getId(), track.getIdentifier(), exception.getMessage()); logger.debug("Guild {}: exception while playing track [{}]: {}", guild.getId(), track.getIdentifier(), exception.getMessage());
LogHandler.log(exception); LogHandler.log(exception);
sendMessageToChannel(MessageFunction.buildSentryErrorMessage(String.format("Error while playing track [%s]: %s", track.getInfo().title, exception.getMessage()))); sendMessageToChannel(MessageFunction.buildSentryErrorMessage(new RuntimeException(String.format("Error while playing track [%s]: %s", track.getInfo().title, exception.getMessage()))));
} }
@Override @Override
@@ -212,11 +212,11 @@ public class MessageFunction {
return messages; return messages;
} }
public static MessageEmbed buildSentryErrorMessage(String error) { public static MessageEmbed buildSentryErrorMessage(Exception ex) {
EmbedBuilder message = new EmbedBuilder(); EmbedBuilder message = new EmbedBuilder();
message.setColor(Color.RED); message.setColor(Color.RED);
message.setTitle(":warning: Error during execution :warning:"); message.setTitle(":warning: Error during execution :warning:");
message.addField("Error message:", error, false); message.addField("Error message:", ex.getMessage(), false);
message.addField("Error ID:", Sentry.getLastEventId().toString(), false); message.addField("Error ID:", Sentry.getLastEventId().toString(), false);
message.setTimestamp(OffsetDateTime.now()); message.setTimestamp(OffsetDateTime.now());