diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-22 16:14:31 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-22 16:14:31 -0400 |
commit | 4f8a0296ddae8a21f8545a16ed2207c2058564a9 (patch) | |
tree | f932a219511ed0d4c3f5537937a81e5ea793514c /lib/Bot/Zulip/Chess.pm | |
parent | 25c30fd82d485f5dc982349fe1270566feb35a4a (diff) | |
download | Bot-Zulip-Chess-4f8a0296ddae8a21f8545a16ed2207c2058564a9.tar.gz Bot-Zulip-Chess-4f8a0296ddae8a21f8545a16ed2207c2058564a9.zip |
don't die if we can't load the state file
Diffstat (limited to 'lib/Bot/Zulip/Chess.pm')
-rw-r--r-- | lib/Bot/Zulip/Chess.pm | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/Bot/Zulip/Chess.pm b/lib/Bot/Zulip/Chess.pm index 83c1e62..57a2f44 100644 --- a/lib/Bot/Zulip/Chess.pm +++ b/lib/Bot/Zulip/Chess.pm @@ -82,13 +82,19 @@ has _chessboard => ( my $board = Chess::Rep->new; my $record = $self->_record_file; if (-e $record) { - chomp(my @lines = $record->slurp); - $self->white_player(shift @lines); - $self->black_player(shift @lines); - for my $turn (@lines) { - my ($white, $black) = split ' ', $turn; - $board->go_move($white) if $white; - $board->go_move($black) if $black; + try { + chomp(my @lines = $record->slurp); + $self->white_player(shift @lines); + $self->black_player(shift @lines); + for my $turn (@lines) { + my ($white, $black) = split ' ', $turn; + $board->go_move($white) if $white; + $board->go_move($black) if $black; + } + } + catch { + warn $_; + $board = Chess::Rep->new; } } $board |