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:
@@ -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] =
|
||||
|
||||
Reference in New Issue
Block a user