Skip to content

Commit

Permalink
GH-131 Add capture exception. (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy authored Oct 25, 2023
1 parent 986a8c2 commit ff52322
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/eternalcode/discordapp/DiscordApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static void main(String... args) throws InterruptedException {
levelService = new LevelService(databaseManager);
}
catch (SQLException exception) {
Sentry.captureException(exception);
LOGGER.error("Failed to connect to database", exception);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.j256.ormlite.jdbc.DataSourceConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import com.zaxxer.hikari.HikariDataSource;
import io.sentry.Sentry;

import java.io.File;
import java.sql.SQLException;
Expand Down Expand Up @@ -77,6 +78,7 @@ public <T, ID> Dao<T, ID> getDao(Class<T> clazz) {
return DaoManager.createDao(this.connectionSource, clazz);
}
catch (SQLException sqlException) {
Sentry.captureException(sqlException);
throw new DataAccessException("Failed to create dao", sqlException);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.eternalcode.discordapp.database.DataAccessException;
import com.eternalcode.discordapp.database.DatabaseManager;
import com.j256.ormlite.dao.Dao;
import io.sentry.Sentry;
import panda.std.function.ThrowingFunction;

import java.sql.SQLException;
Expand Down Expand Up @@ -47,6 +48,7 @@ public <R> CompletableFuture<R> action(ThrowingFunction<Dao<T, ID>, R, SQLExcept
return action.apply(dao);
}
catch (SQLException sqlException) {
Sentry.captureException(sqlException);
throw new DataAccessException("Failed to execute database action", sqlException);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.discordapp.database.DatabaseManager;
import com.eternalcode.discordapp.database.repository.AbstractRepository;
import com.j256.ormlite.table.TableUtils;
import io.sentry.Sentry;

import java.sql.SQLException;
import java.util.List;
Expand All @@ -20,6 +21,7 @@ public static LevelRepository create(DatabaseManager databaseManager) {
TableUtils.createTableIfNotExists(databaseManager.getConnectionSource(), LevelWrapper.class);
}
catch (SQLException sqlException) {
Sentry.captureException(sqlException);
throw new DataAccessException("Failed to create table", sqlException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.discordapp.database.DatabaseManager;
import com.eternalcode.discordapp.database.repository.AbstractRepository;
import com.j256.ormlite.table.TableUtils;
import io.sentry.Sentry;

import java.sql.SQLException;
import java.util.List;
Expand All @@ -20,6 +21,7 @@ public static ExperienceRepository create(DatabaseManager databaseManager) {
TableUtils.createTableIfNotExists(databaseManager.getConnectionSource(), ExperienceWrapper.class);
}
catch (SQLException sqlException) {
Sentry.captureException(sqlException);
throw new DataAccessException("Failed to create table", sqlException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.eternalcode.discordapp.leveling.experience.ExperienceConfig;
import com.eternalcode.discordapp.leveling.experience.ExperienceService;
import com.eternalcode.discordapp.leveling.experience.data.UsersVoiceActivityData;
import io.sentry.Sentry;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -40,6 +41,7 @@ public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
this.configManager.save(this.usersVoiceActivityData);
}
catch (Exception exception) {
Sentry.captureException(exception);
throw new DataAccessException("Something went wrong while updating voice experience", exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eternalcode.discordapp.leveling.games;

import com.eternalcode.discordapp.config.ConfigManager;
import io.sentry.Sentry;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.FileUpload;
Expand Down Expand Up @@ -76,6 +77,7 @@ private void sendCodeImageMessage(BufferedImage image) {
ImageIO.write(image, "png", byteArrayOutputStream);
}
catch (IOException exception) {
Sentry.captureException(exception);
exception.printStackTrace();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.eternalcode.discordapp.config.AppConfig;
import com.eternalcode.discordapp.config.ConfigManager;
import io.sentry.Sentry;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.User;
Expand Down Expand Up @@ -51,6 +52,7 @@ public String createReview(Guild guild, String url, JDA jda) {
return "Review created";
}
catch (IOException exception) {
Sentry.captureException(exception);
exception.printStackTrace();
return "Something went wrong";
}
Expand Down Expand Up @@ -208,6 +210,7 @@ public void archiveMergedPullRequest(JDA jda) {
}
}
catch (IOException exception) {
Sentry.captureException(exception);
exception.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.sentry.Sentry;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand Down Expand Up @@ -57,6 +58,7 @@ public static List<String> getReviewers(GitHubPullRequest pullRequest, String gi
return reviewers;
}
catch (IOException exception) {
Sentry.captureException(exception);
exception.printStackTrace();
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.eternalcode.discordapp.review.GitHubReviewUser;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import io.sentry.Sentry;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void execute(SlashCommandEvent event) {
}
catch (Exception exception) {
event.reply("An error occurred while adding user to the system").setEphemeral(true).queue();
Sentry.captureException(exception);
exception.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.discordapp.review.GitHubReviewUser;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import io.sentry.Sentry;
import net.dv8tion.jda.api.EmbedBuilder;

import java.util.List;
Expand Down Expand Up @@ -37,6 +38,7 @@ public void execute(SlashCommandEvent event) {
}
catch (Exception exception) {
event.reply("An error occurred while listing the users").setEphemeral(true).queue();
Sentry.captureException(exception);
exception.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.eternalcode.discordapp.review.GitHubReviewService;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import io.sentry.Sentry;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void execute(SlashCommandEvent event) {
}
catch (Exception exception) {
event.reply("An error occurred while removing the user from the system").setEphemeral(true).queue();
Sentry.captureException(exception);
exception.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.eternalcode.discordapp.database.repository.AbstractRepository;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.table.TableUtils;
import io.sentry.Sentry;

import java.sql.SQLException;
import java.util.List;
Expand All @@ -22,6 +23,7 @@ public static UserRepository create(DatabaseManager databaseManager) {
TableUtils.createTableIfNotExists(databaseManager.getConnectionSource(), UserWrapper.class);
}
catch (SQLException sqlException) {
Sentry.captureException(sqlException);
throw new DataAccessException("Failed to create table", sqlException);
}

Expand Down

0 comments on commit ff52322

Please sign in to comment.