Skip to content

Commit 55d5896

Browse files
fix: add error handling for invalid fen positions
1 parent 942cae8 commit 55d5896

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/components/Misc/PlaySetupModal.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Image from 'next/image'
2+
import { Chess } from 'chess.ts'
3+
import toast from 'react-hot-toast'
24
import { useRouter } from 'next/router'
35
import { AnimatePresence } from 'framer-motion'
46
import { useCallback, useContext, useState } from 'react'
@@ -97,10 +99,15 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
9799

98100
const start = useCallback(
99101
(color: Color | undefined) => {
100-
setPlaySetupModalProps(undefined)
101-
102102
const player = color ?? ['white', 'black'][Math.floor(Math.random() * 2)]
103103

104+
if (fen && !new Chess().validateFen(fen).valid) {
105+
toast.error('Invalid Starting FEN provided')
106+
return
107+
}
108+
109+
setPlaySetupModalProps(undefined)
110+
104111
if (props.playType == 'againstMaia') {
105112
push({
106113
pathname: '/play/maia',

0 commit comments

Comments
 (0)