Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Error Type #428

Open
LandonSchropp opened this issue Jul 23, 2023 · 0 comments
Open

Move Error Type #428

LandonSchropp opened this issue Jul 23, 2023 · 0 comments

Comments

@LandonSchropp
Copy link

I wanted to toss this suggestion in the mix before 1.0.0 is released. 馃檪

It'd be great if Chess.js could throw a specific error type if an illegal move is made, rather than a generic error. Then, detecting an illegal move could look something like this:

function reduceLegalMove(fen: string, { from, to }: MoveEvent): string {
  const chess = new Chess(fen);

  try {
    chess.move({ from, to });
  }
  catch (error) {
    if (error instanceof IllegalMoveError) {
      return fen;
    }

    throw error;
  }

  return chess.fen();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant