From 4f8a0296ddae8a21f8545a16ed2207c2058564a9 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 22 Oct 2014 16:14:31 -0400 Subject: don't die if we can't load the state file --- lib/Bot/Zulip/Chess.pm | 20 +++++++++++++------- 1 file 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 -- cgit v1.2.3