refactor(io): change GameContextImport return type from Option to Either

Update GameContextImport trait to return Either[String, GameContext] instead of
Option[GameContext] to provide better error context during parsing. Update FenParser
implementation to convert Option to Either using toRight().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-05 12:33:13 +02:00
parent e2fe56ea87
commit f6f05ff2a1
4 changed files with 802 additions and 5 deletions
@@ -2,8 +2,6 @@ package de.nowchess.io
import de.nowchess.api.game.GameContext
trait GameContextImport {
trait GameContextImport:
def importGameContext(input: String): Option[GameContext]
}
def importGameContext(input: String): Either[String, GameContext]
@@ -28,7 +28,8 @@ object FenParser extends GameContextImport:
moves = List.empty
)
def importGameContext(input: String): Option[GameContext] = parseFen(input)
def importGameContext(input: String): Either[String, GameContext] =
parseFen(input).toRight("Invalid FEN string")
/** Parse active color ("w" or "b"). */
private def parseColor(s: String): Option[Color] =