From d1fc7ecec1f37bc070259e7cf42e534b0c5c3c59 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Thu, 29 Feb 2024 14:37:12 +0700 Subject: [PATCH] Remove unnecessary try catch as we fixed it Fix in: https://github.com/lichess-org/scalachess/pull/511 and https://github.com/lichess-org/scalachess/pull/514 --- src/main/scala/Chess.scala | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/scala/Chess.scala b/src/main/scala/Chess.scala index 29b19820..2d4cf2c6 100644 --- a/src/main/scala/Chess.scala +++ b/src/main/scala/Chess.scala @@ -6,39 +6,26 @@ import chess.opening.{ Opening, OpeningDb } import chess.Square import chess.bitboard.Bitboard import chess.variant.{ Crazyhouse, Variant } -import com.typesafe.scalalogging.Logger import cats.syntax.option.* import ipc.* object Chess: - private val logger = Logger(getClass) - def apply(req: ClientOut.AnaMove): ClientIn = Monitor.time(_.chessMoveTime): - try - chess - .Game(req.variant.some, req.fen.some)(req.orig, req.dest, req.promotion) - .map((game, move) => makeNode(game, Uci.WithSan(Uci(move), move.san), req.path, req.chapterId)) - .getOrElse(ClientIn.StepFailure) - catch - case e: java.lang.ArrayIndexOutOfBoundsException => - logger.warn(s"${req.fen} ${req.variant} ${req.orig}${req.dest}", e) - ClientIn.StepFailure + chess + .Game(req.variant.some, req.fen.some)(req.orig, req.dest, req.promotion) + .map((game, move) => makeNode(game, Uci.WithSan(Uci(move), move.san), req.path, req.chapterId)) + .getOrElse(ClientIn.StepFailure) def apply(req: ClientOut.AnaDrop): ClientIn = Monitor.time(_.chessMoveTime): - try - chess - .Game(req.variant.some, req.fen.some) - .drop(req.role, req.square) - .map((game, drop) => makeNode(game, Uci.WithSan(Uci(drop), drop.san), req.path, req.chapterId)) - .getOrElse(ClientIn.StepFailure) - catch - case e: java.lang.ArrayIndexOutOfBoundsException => - logger.warn(s"${req.fen} ${req.variant} ${req.role}@${req.square}", e) - ClientIn.StepFailure + chess + .Game(req.variant.some, req.fen.some) + .drop(req.role, req.square) + .map((game, drop) => makeNode(game, Uci.WithSan(Uci(drop), drop.san), req.path, req.chapterId)) + .getOrElse(ClientIn.StepFailure) def apply(req: ClientOut.AnaDests): ClientIn.Dests = Monitor.time(_.chessDestTime):