From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RP_MATCHES_RCVD,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E6E92633824 for ; Mon, 29 Feb 2016 01:41:11 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/8] distinguish error messages intended for users vs developers Date: Mon, 29 Feb 2016 01:41:03 +0000 Message-Id: <20160229014107.7396-5-e@80x24.org> In-Reply-To: <20160229014107.7396-1-e@80x24.org> References: <20160229014107.7396-1-e@80x24.org> List-Id: For error messages intended to show user error (e.g. giving invalid options), we add a newline ("\n") at the end to polluting the output with location information. However, for diagnosing non-user-triggered errors, we should show the location of where the error occured. --- lib/PublicInbox/Config.pm | 6 +++--- lib/PublicInbox/Daemon.pm | 18 ++++++++---------- lib/PublicInbox/NNTP.pm | 2 +- lib/PublicInbox/WWW.pm | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index b511638..f84a955 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -73,7 +73,7 @@ sub git_config_dump { my @cmd = (qw/git config/, "--file=$file", '-l'); my $cmd = join(' ', @cmd); my $pid = open(my $fh, '-|', @cmd); - defined $pid or die "$cmd failed: $!\n"; + defined $pid or die "$cmd failed: $!"; my %rv; foreach my $line (<$fh>) { chomp $line; @@ -90,8 +90,8 @@ sub git_config_dump { $rv{$k} = $v; } } - close $fh or die "failed to close ($cmd) pipe: $!\n"; - $? and warn "$$ $cmd exited with: ($pid) $?\n"; + close $fh or die "failed to close ($cmd) pipe: $!"; + $? and warn "$$ $cmd exited with: ($pid) $?"; \%rv; } diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index b8482d3..45c1563 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -67,12 +67,12 @@ sub daemon_prepare ($) { warn "error binding $l: $!\n"; } } - die 'No listeners bound' unless @listeners; + die "No listeners bound\n" unless @listeners; } sub daemonize () { - chdir '/' or die "chdir failed: $!\n"; - open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!\n"; + chdir '/' or die "chdir failed: $!"; + open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!"; return unless (defined $pid_file || defined $group || defined $user || $daemonize); @@ -238,12 +238,10 @@ sub do_fork () { my $new = POSIX::SigSet->new; $new->fillset; my $old = POSIX::SigSet->new; - POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new, $old) or - die "SIG_BLOCK: $!\n"; + POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new, $old) or die "SIG_BLOCK: $!"; my $pid = fork; my $err = $!; - POSIX::sigprocmask(&POSIX::SIG_SETMASK, $old) or - die "SIG_SETMASK: $!\n"; + POSIX::sigprocmask(&POSIX::SIG_SETMASK, $old) or die "SIG_SETMASK: $!"; ($pid, $err); } @@ -254,7 +252,7 @@ sub upgrade_aborted ($) { return unless $pid_file; my $file = $pid_file; - $file =~ s/\.oldbin\z// or die "BUG: no '.oldbin' suffix in $file\n"; + $file =~ s/\.oldbin\z// or die "BUG: no '.oldbin' suffix in $file"; unlink_pid_file_safe_ish($$, $pid_file); $pid_file = $file; eval { write_pid($pid_file) }; @@ -289,8 +287,8 @@ sub unlink_pid_file_safe_ish ($$) { } sub master_loop { - pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!\n"; - pipe(my ($r, $w)) or die "failed to create self-pipe: $!\n"; + pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!"; + pipe(my ($r, $w)) or die "failed to create self-pipe: $!"; IO::Handle::blocking($w, 0); my $set_workers = $worker_processes; my @caught; diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index bcce770..fbf8f7f 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -229,7 +229,7 @@ sub parse_time ($$;$) { use Time::Local qw(); my ($hh, $mm, $ss) = unpack('A2A2A2', $time); if (defined $gmt) { - $gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt\n"; + $gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt"; $gmt = 1; } my @now = $gmt ? gmtime : localtime; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 2da819b..98e33fd 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -244,7 +244,7 @@ sub get_thread { sub ctx_get { my ($ctx, $key) = @_; my $val = $ctx->{$key}; - (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable\n"; + (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable"; $val; } -- EW