From 9395ae73b978d7bd8c069c4742265323220c9055 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 6 Jul 2024 00:24:06 +0100 Subject: [PATCH] use Sentry hints --- .../cc/fascinated/bat/common/EmbedUtils.java | 1 - .../fascinated/bat/service/CommandService.java | 10 ++++++++++ .../cc/fascinated/bat/service/EventService.java | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/bat/common/EmbedUtils.java b/src/main/java/cc/fascinated/bat/common/EmbedUtils.java index 56f36bb..ad594ce 100644 --- a/src/main/java/cc/fascinated/bat/common/EmbedUtils.java +++ b/src/main/java/cc/fascinated/bat/common/EmbedUtils.java @@ -69,7 +69,6 @@ public class EmbedUtils { if (channel != null) { channel.sendMessageEmbeds(embed.build()).queue(); } - Sentry.captureException(ex); // Capture the exception return embed; } } diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 30bc791..f40a88b 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -8,6 +8,8 @@ import cc.fascinated.bat.config.Config; import cc.fascinated.bat.features.FeatureProfile; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; +import io.sentry.Hint; +import io.sentry.Sentry; import lombok.Getter; import lombok.NonNull; import lombok.extern.log4j.Log4j2; @@ -232,6 +234,14 @@ public class CommandService extends ListenerAdapter { } catch (Exception ex) { log.error("An error occurred while executing command \"{}\"", command.getInfo().getName(), ex); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); + + Hint hint = new Hint(); + hint.set("command", command.getInfo().getName()); + hint.set("user", user.getId()); + if (guild != null) { + hint.set("guild", guild.getId()); + } + Sentry.captureException(ex, hint); // Capture the exception } } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/service/EventService.java b/src/main/java/cc/fascinated/bat/service/EventService.java index fa7d7b0..c9e3e55 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -5,6 +5,8 @@ import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.DiscordMessage; +import io.sentry.Hint; +import io.sentry.Sentry; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.entities.Invite; @@ -165,6 +167,13 @@ public class EventService extends ListenerAdapter { } catch (Exception ex) { log.error("An error occurred while handling a modal interaction.", ex); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); + Hint hint = new Hint(); + hint.set("componentId", event.getComponentId()); + hint.set("user", user.getId()); + if (event.getGuild() != null) { + hint.set("guild", event.getGuild().getId()); + } + Sentry.captureException(ex, hint); // Capture the exception } } @@ -183,6 +192,13 @@ public class EventService extends ListenerAdapter { } catch (Exception ex) { log.error("An error occurred while handling a modal interaction.", ex); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); + Hint hint = new Hint(); + hint.set("modalId", event.getModalId()); + hint.set("user", user.getId()); + if (event.getGuild() != null) { + hint.set("guild", event.getGuild().getId()); + } + Sentry.captureException(ex, hint); // Capture the exception } }