actually handle errors

This commit is contained in:
Roscoe 2025-05-16 16:27:46 +01:00
commit d87efe6757
Signed by: RoscoeDaWah
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE

View file

@ -59,8 +59,19 @@ public class Pgn2Gif extends ApplicationCommand {
}
// Load PGN from file
PgnHolder pgn = new PgnHolder("./temp/pgn/" + attachment.getFileName());
Game game = null;
try {
outputFile = pgnToGif(pgn);
game = pgnToGame(pgn);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (pgn.getGames().getFirst().getHalfMoves().isEmpty()) {
log.debug("Invalid PGN!");
event.getHook().sendMessage("Invalid PGN!").queue();
}
try {
outputFile = gameToGif(game);
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -80,11 +91,9 @@ public class Pgn2Gif extends ApplicationCommand {
});
}
private static File pgnToGif(PgnHolder pgn) throws Exception {
private static File gameToGif(Game game) throws Exception {
ChessRenderer renderer = new ChessRenderer(ChessThemeLibrary.GREEN_THEME, 60);
Game game = pgnToGame(pgn);
String boardID = String.valueOf(Instant.now().toEpochMilli());
game.loadMoveText();
MoveList moves = game.getHalfMoves();
Board board = new Board();