Skip to content

Commit

Permalink
Make sure errors display correctly.
Browse files Browse the repository at this point in the history
Requires passing through Locale::TextDomain in PGXN::Manager::Maint.
  • Loading branch information
theory committed Aug 31, 2015
1 parent e991859 commit ee1f36e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -11,7 +11,7 @@ Revision history for Perl extension PGXN::Manager
- Fixed warnings on Perl 5.20.
- Fixed encoding issues with Perl 5.20 and DBD::Pg 3.0.
- Fixed pgxn_maint so that reindexing failures are reported on the
command- line and the exit value set to the number of failures.
command-line and the exit value set to the number of failures.
Previously it would fail silently.
- Added the ability to pass the path to a zip archive to `pgxn_maint
index`. Previously, you had to pass a distribution name and release
Expand Down
2 changes: 2 additions & 0 deletions lib/PGXN/Manager/Locale.pm
Expand Up @@ -262,6 +262,8 @@ make installcheck PGDATABASE=postgres
<p>Good hacking!</p>},

'Sorry, but this URL is invalid. I think you either want <a href="$url">/pub/</a> or to run PGXN Manager behind a reverse proxy server. See <a href="https://github.com/pgxn/pgxn-manager/blob/master/README.md">the README</a> for details.' => 'Sorry, but this URL is invalid. I think you either want <a href="$url">/pub/</a> or to run PGXN Manager behind a reverse proxy server. See <a href="https://github.com/pgxn/pgxn-manager/blob/master/README.md">the README</a> for details.',

'“[_1] [_2]” is not a known release' => '“[_1] [_2]” is not a known release',
);

sub accept {
Expand Down
25 changes: 17 additions & 8 deletions lib/PGXN/Manager/Maint.pm
Expand Up @@ -6,6 +6,7 @@ use Moose;
use File::Spec;
use File::Path qw(make_path remove_tree);
use File::Basename qw(dirname basename);
use Encode qw(encode_utf8);
use Carp;
use namespace::autoclean;

Expand Down Expand Up @@ -96,6 +97,15 @@ sub update_users {
return $self;
}

sub _handle_error {
my $self = shift;
my $l = PGXN::Manager::Locale->get_handle;
my $err = $l->maketext(@_);
$err =~ s{<br />}{}g;
warn encode_utf8 $err, "\n";
$self->exitval( $self->exitval + 1 );
}

sub reindex {
my ($self, @args) = @_;
my $pgxn = PGXN::Manager->instance;
Expand All @@ -120,8 +130,7 @@ sub reindex {
creator => '',
);
unless ($dist->extract_meta) {
warn $dist->error;
$self->exitval( $self->exitval + 1 );
$self->_handle_error($dist->error);
next;
}

Expand All @@ -143,16 +152,17 @@ sub reindex {
# Find the user who uploaded it.
my ($user) = $dbh->selectrow_array($sth, undef, $name, $version);
unless ($user) {
warn "$name $version is not a known release\n";
$self->exitval( $self->exitval + 1 );
$self->_handle_error(
'“[_1] [_2]” is not a known release',
$name, $version
);
next;
}

# Do the work.
$dist->creator($user);
unless ($dist->reindex) {
warn $dist->error;
$self->exitval( $self->exitval + 1 );
$self->_handle_error($dist->error);
}
}
});
Expand Down Expand Up @@ -184,8 +194,7 @@ sub reindex_all {
creator => $user,
);
unless ($dist->reindex) {
warn $dist->error;
$self->exitval( $self->exitval + 1 );
$self->_handle_error($dist->error);
}
}
});
Expand Down
7 changes: 4 additions & 3 deletions t/maint.t
Expand Up @@ -297,7 +297,8 @@ REINDEX: {

# Make sure we warn for an unknown release.
local $SIG{__WARN__} = sub {
is shift, "nonexistent 0.0.1 is not a known release\n",
no utf8;
is shift, "“nonexistent 0.0.1” is not a known release\n",
'Should get warning for non-existant distribution';
};
ok $maint->reindex(nonexistent => '0.0.1'), 'Reindex nonexistent release';
Expand All @@ -306,7 +307,7 @@ REINDEX: {

# Make sure we emit a message and set exitval for a failed reindex.
$mocker->mock(reindex => sub {
shift->error(['This is an error: ', 'ha']);
shift->error(['This is an error: [_1]', 'ha']);
return 0;
});
local $SIG{__WARN__} = sub {
Expand Down Expand Up @@ -357,7 +358,7 @@ REINDEX: {

# Make sure we emit a message and set exitval for a failed reindex.
$mocker->mock(reindex => sub {
shift->error(['This is an error: ', 'ha']);
shift->error(['This is an error: [_1]', 'ha']);
return 0;
});
local $SIG{__WARN__} = sub {
Expand Down

0 comments on commit ee1f36e

Please sign in to comment.