]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei up: more error checking for config loading
authorEric Wong <e@80x24.org>
Mon, 19 Apr 2021 23:49:00 +0000 (14:49 -0900)
committerEric Wong <e@80x24.org>
Tue, 20 Apr 2021 19:02:46 +0000 (19:02 +0000)
We'll support editing the saved search config file, so user
errors may happen and we need to throw sensible errors in that
case.

lib/PublicInbox/LeiUp.pm

index 63a7f996174f1cb96b3d3618adf537ee6dcb0f01..e80ccf57f3cceecc12f35999460c7a78fdfc86ef 100644 (file)
@@ -14,24 +14,27 @@ sub lei_up {
        my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return;
        my $mset_opt = $lei->{mset_opt} = { relevance => -2 };
        $mset_opt->{limit} = $lei->{opt}->{limit} // 10000;
+       my $f = $lss->{'-f'};
        my $q = $mset_opt->{q_raw} = $lss->{-cfg}->{'lei.q'} //
-                               return $lei->fail("lei.q unset in $lss->{-f}");
+                               return $lei->fail("lei.q unset in $f");
        my $lse = $lei->{lse} // die 'BUG: {lse} missing';
        if (ref($q)) {
                $mset_opt->{qstr} = $lse->query_argv_to_string($lse->git, $q);
        } else {
                $lse->query_approxidate($lse->git, $mset_opt->{qstr} = $q);
        }
-       $lei->{opt}->{output} = $lss->{-cfg}->{'lei.q.output'} //
-               return $lei->fail("lei.q.output unset in $lss->{-f}");
-
+       my $o = $lei->{opt}->{output} = $lss->{-cfg}->{'lei.q.output'} //
+               return $lei->fail("lei.q.output unset in $f");
+       ref($o) and return $lei->fail("multiple values of lei.q.output in $f");
        for my $k (qw(only include exclude)) {
                my $v = $lss->{-cfg}->get_all("lei.q.$k") // next;
                $lei->{opt}->{$k} = $v;
        }
        for my $k (qw(external local remote
                        import-remote import-before threads)) {
-               my $v = $lss->{-cfg}->{"lei.q.$k"} // next;
+               my $c = "lei.q.$k";
+               my $v = $lss->{-cfg}->{$c} // next;
+               ref($v) and return $lei->fail("multiple values of $c in $f");
                $lei->{opt}->{$k} = $v;
        }
        $lei->{lss} = $lss; # for LeiOverview->new