From 7893b78fd691ef1e9b503e44174ff53278b02554 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 16 Oct 2021 01:00:58 +0000 Subject: lei: more eval guards for die on failure Relying on $lei->fail is unsustainable since there'll always be parts of our code and dependencies which can trigger die() and break the event loop. --- lib/PublicInbox/LeiQuery.pm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'lib/PublicInbox/LeiQuery.pm') diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index c65b00ca..ec2ece05 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -55,19 +55,17 @@ sub _start_query { # used by "lei q" and "lei up" } sub qstr_add { # PublicInbox::InputPipe::consume callback for --stdin - my ($self) = @_; # $_[1] = $rbuf - if (defined($_[1])) { - $_[1] eq '' and return eval { - $self->fchdir or return; - $self->{mset_opt}->{q_raw} = $self->{mset_opt}->{qstr}; - $self->{lse}->query_approxidate($self->{lse}->git, - $self->{mset_opt}->{qstr}); - _start_query($self); - }; - $self->{mset_opt}->{qstr} .= $_[1]; - } else { - $self->fail("error reading stdin: $!"); - } + my ($lei) = @_; # $_[1] = $rbuf + $_[1] // $lei->fail("error reading stdin: $!"); + return $lei->{mset_opt}->{qstr} .= $_[1] if $_[1] ne ''; + eval { + $lei->fchdir; + $lei->{mset_opt}->{q_raw} = $lei->{mset_opt}->{qstr}; + $lei->{lse}->query_approxidate($lei->{lse}->git, + $lei->{mset_opt}->{qstr}); + _start_query($lei); + }; + $lei->fail($@) if $@; } sub lxs_prepare { -- cgit v1.2.3-24-ge0c7