unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] lei up: more error checking for config loading
Date: Mon, 19 Apr 2021 14:49:00 -0900	[thread overview]
Message-ID: <20210419234901.4084-4-e@80x24.org> (raw)
In-Reply-To: <20210419234901.4084-1-e@80x24.org>

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 | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index 63a7f996..e80ccf57 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -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

  parent reply	other threads:[~2021-04-19 23:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 23:48 [PATCH 0/4] "lei up --all=local" support Eric Wong
2021-04-19 23:48 ` [PATCH 1/4] lei up: fix help output and ARGV handling Eric Wong
2021-04-19 23:48 ` [PATCH 2/4] config: favor ->get_all when possible Eric Wong
2021-04-19 23:49 ` Eric Wong [this message]
2021-04-19 23:49 ` [PATCH 4/4] lei up: support --all=local Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210419234901.4084-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).