Skip to content

Commit

Permalink
xxx package errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Apr 30, 2023
1 parent cff0645 commit af03add
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 136 deletions.
83 changes: 83 additions & 0 deletions lib/PAUSE/Indexer/Context.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,92 @@ sub add_package_warning {
text => $warning,
};

$Logger->log([
"adding package warning to %s: %s",
$package_obj->{PACKAGE},
$list->[-1],
]);

return;
}

has package_status => (
is => 'bare',
reader => '_package_status',
default => sub { {} },
);

sub _set_package_error {
my ($self, $package_obj, $status) = @_;

# XXX remove this block when ->index_status is dead
$package_obj->{FIO}{DIO}->index_status(
$self,
$package_obj->{PACKAGE},
$package_obj->{PP}{version},
$package_obj->{PP}{infile},
2, # OK
$status->{header},
);

$self->_package_status->{ $package_obj->{PACKAGE} } = {
is_success => 0,
filename => $package_obj->{PP}{infile},
version => $package_obj->{PP}{version},
header => $status->{header},
body => $status->{body},
};

$Logger->log([
"set error status for %s",
$package_obj->{PACKAGE},
]);

return;
}

sub record_package_indexing {
my ($self, $package_obj) = @_;

# XXX remove this block when ->index_status is dead
$package_obj->{FIO}{DIO}->index_status(
$self,
$package_obj->{PACKAGE},
$package_obj->{PP}{version},
$package_obj->{PP}{infile},
1, # OK
"it worked",
);

$self->_package_status->{ $package_obj->{PACKAGE} } = {
is_success => 1,
filename => $package_obj->{PP}{infile},
version => $package_obj->{PP}{version},
header => "package indexed successfully",
body => "the package was indexed successfully",
};

$Logger->log([
"set OK status for %s",
$package_obj->{PACKAGE},
]);

return;
}

sub abort_indexing_package {
my ($self, $package_obj, $error) = @_;

$Logger->log("abort indexing $package_obj->{PACKAGE}");

$self->_set_package_error($package_obj, $error);

die PAUSE::Indexer::Abort::Package->new({
message => $error->{header},
public => 1,
});
}

sub warnings_for_all_packages {
my ($self) = @_;

Expand Down
125 changes: 99 additions & 26 deletions lib/PAUSE/Indexer/Errors.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@ use v5.12.0;
use warnings;

use Sub::Exporter -setup => {
exports => [ 'ERROR' ],
groups => { default => [ 'ERROR' ] },
exports => [ qw( DISTERROR PKGERROR ) ],
groups => { default => [ qw( DISTERROR PKGERROR ) ] },
};

my %ERROR;
sub dist_error;
sub pkg_error;

sub public_error {
my ($name, $arg) = @_;
$ERROR{$name} = {
ident => $name,
public => 1,
%$arg,
};
}

public_error blib => {
dist_error blib => {
header => 'archive contains a "blib" directory',
body => <<'EOF'
The distribution contains a blib/ directory and is therefore not being indexed.
Hint: try 'make dist'.
EOF
};

public_error multiroot => {
dist_error multiroot => {
header => 'archive has multiple roots',
body => sub {
my ($dist) = @_;
Expand All @@ -38,7 +30,7 @@ EOF
},
};

public_error no_distname_permission => {
dist_error no_distname_permission => {
header => 'missing permissions on distname package',
body => sub {
my ($dist) = @_;
Expand All @@ -57,7 +49,7 @@ EOF
},
};

public_error no_meta => {
dist_error no_meta => {
header => "no META.yml or META.json found",
body => <<'EOF',
Your archive didn't contain a META.json or META.yml file. You need to include
Expand All @@ -66,7 +58,7 @@ ExtUtils::MakeMaker can help with this.
EOF
};

public_error single_pm => {
dist_error single_pm => {
header => 'dist is a single-.pm-file upload',
body => <<"EOF",
You've uploaded a compressed .pm file without a META.json, a build tool, or the
Expand All @@ -75,15 +67,15 @@ no longer is. Please use a CPAN distribution building tool.
EOF
};

public_error unstable_release => {
dist_error unstable_release => {
header => 'META release_status is not stable',
body => <<'EOF',
Your META file provides a release status other than "stable", so this
distribution will not be indexed.
EOF
};

public_error worldwritable => {
dist_error worldwritable => {
header => 'archive has world writable files',
body => sub {
my ($dist) = @_;
Expand All @@ -95,29 +87,110 @@ EOF
},
};

public_error xact_fail => {
dist_error xact_fail => {
header => "ERROR: Database error occurred during index update",
body => <<'EOF',
This distribution was not indexed due to database errors. You can request
another indexing attempt be made by logging into https://pause.perl.org/
EOF
};

sub ERROR {
pkg_error bad_package_name => {
header => 'Not indexed because of invalid package name.',
body => <<'EOF',
This package wasn't indexed because its name doesn't conform to standard
naming. Basically: one or more valid identifiers, separated by double colons
(::).
EOF
};

pkg_error no_permission => {
header => 'Not indexed because the required permissions were missing.',
body => <<'EOF',
This package wasn't indexed because you don't have permission to use this
package name. Hint: you can always find the legitimate maintainer(s) on PAUSE
under "View Permissions".
EOF
};

pkg_error version_openerr => {
header => 'Not indexed because of version handling error.',
body => <<'EOF',
The PAUSE indexer was not able to read the file.
EOF
};

pkg_error version_parse => {
header => 'Not indexed because of version parsing error.',
body => <<'EOF',
The PAUSE indexer was not able to parse the file.
Note: the indexer is running in a Safe compartement and cannot provide the full
functionality of perl in the VERSION line. It is trying hard, but sometime it
fails. As a workaround, please consider writing a META.yml that contains a
"provides" attribute, or contact the CPAN admins to investigate (yet another)
workaround against "Safe" limitations.
EOF
};

pkg_error version_too_long => {
header => 'Not indexed because the version string was too long.',
body => <<'EOF',
The maximum length of a version string is 16 bytes, which is already quite
long. Please consider picking a shorter version.
EOF
};

pkg_error wtf => {
header => 'Not indexed: something surprising happened.',
body => <<'EOF',
The PAUSE indexer couldn't index this package. It ended up with a weird
internal state, like thinking your package name was empty or your version was
undefined. If you see this, you should probably contact the PAUSE admins.
EOF
};

my %DIST_ERROR;
my %PKG_ERROR;

sub DISTERROR {
my ($ident) = @_;

my $error = $DIST_ERROR{$ident};
unless ($error) {
Carp::confess("requested unknown distribution error: $ident");
}

return $error;
}

sub PKGERROR {
my ($ident) = @_;

my $error = PAUSE::Indexer::Errors->error_named($ident);
my $error = $PKG_ERROR{$ident};
unless ($error) {
Carp::confess("requested unknown error: $ident");
Carp::confess("requested unknown package error: $ident");
}

return $error;
}

sub error_named {
my ($self, $ident) = @_;
sub dist_error {
my ($name, $arg) = @_;
$DIST_ERROR{$name} = {
ident => $name,
public => 1,
%$arg,
};
}

return $ERROR{$ident};
sub pkg_error {
my ($name, $arg) = @_;
$PKG_ERROR{$name} = {
ident => $name,
public => 1,
%$arg,
};
}

1;
15 changes: 8 additions & 7 deletions lib/PAUSE/dist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ sub examine_dist {
}
} elsif ($dist =~ /\.pm\.(?:Z|gz|bz2)$/) {
$self->{SUFFIX} = "N/A";
$ctx->abort_indexing_dist(ERROR('single_pm'));
$ctx->abort_indexing_dist(DISTERROR('single_pm'));
} elsif ($dist =~ /\.zip$/) {
$self->{SUFFIX} = "zip";
my $unzipbin = $self->hub->{UNZIPBIN};
Expand Down Expand Up @@ -573,7 +573,7 @@ sub check_blib {
my ($self, $ctx) = @_;
if (grep m|^[^/]+/blib/|, @{$self->{MANIFOUND}}) {
$self->{HAS_BLIB}++;
$ctx->abort_indexing_dist(ERROR('blib'));
$ctx->abort_indexing_dist(DISTERROR('blib'));
}
# sometimes they package their stuff deep inside a hierarchy
my @found = @{$self->{MANIFOUND}};
Expand All @@ -598,7 +598,7 @@ sub check_blib {
# more than one entry in this directory means final check
if (grep m|^blib/|, @found) {
$self->{HAS_BLIB}++;
$ctx->abort_indexing_dist(ERROR('blib'));
$ctx->abort_indexing_dist(DISTERROR('blib'));
}
last DIRDOWN;
}
Expand All @@ -610,7 +610,7 @@ sub check_multiple_root {
my @top = grep { s|/.*||; !$seen{$_}++ } map { $_ } @{$self->{MANIFOUND}};
if (@top > 1) {
$self->{HAS_MULTIPLE_ROOT} = \@top;
$ctx->abort_indexing_dist(ERROR('multiroot'));
$ctx->abort_indexing_dist(DISTERROR('multiroot'));
} else {
$self->{DISTROOT} = $top[0];
}
Expand All @@ -633,7 +633,7 @@ sub check_world_writable {

$Logger->log([ "archive has world writable files: %s", [ sort @ww ] ]);
$self->{HAS_WORLD_WRITABLE} = \@ww;
$ctx->abort_indexing_dist(ERROR('worldwritable'));
$ctx->abort_indexing_dist(DISTERROR('worldwritable'));
}

sub filter_pms {
Expand Down Expand Up @@ -827,6 +827,7 @@ sub examine_pms {
}

if ($indexing_method) {
$Logger->log("indexing via $indexing_method");
$self->$indexing_method($ctx, $pmfiles, $provides);
} else {
$ctx->alert("Couldn't determine an indexing method!");
Expand Down Expand Up @@ -921,7 +922,7 @@ sub extract_readme_and_meta {

unless ($json || $yaml) {
$self->{METAFILE} = "No META.yml or META.json found";
$ctx->abort_indexing_dist(ERROR('no_meta'));
$ctx->abort_indexing_dist(DISTERROR('no_meta'));
return;
}

Expand Down Expand Up @@ -971,7 +972,7 @@ sub check_indexability {

if (($self->{META_CONTENT}{release_status} // 'stable') ne 'stable') {
# META.json / META.yml declares it's not stable; do not index!
$ctx->abort_indexing_dist(ERROR('unstable_release'));
$ctx->abort_indexing_dist(DISTERROR('unstable_release'));
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PAUSE/mldistwatch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ sub _do_the_database_work {
my $main_pkg = $dio->_package_governing_permission;

if ($self->permissions->userid_has_permissions_on_package($dio->{USERID}, $main_pkg)) {
$dbh->commit;
my $ok = $dbh->commit;
} else {
$ctx->alert("Uploading user has no permissions on package $main_pkg");
$ctx->add_dist_error(ERROR('no_distname_permission'));
$ctx->add_dist_error(DISTERROR('no_distname_permission'));
$dbh->rollback;
}

Expand Down Expand Up @@ -493,7 +493,7 @@ sub maybe_index_dist {
if ($attempt == 3) {
$Logger->log_debug("tried $attempt times to do db work, but all failed");
$ctx->alert("database errors while indexing");
$ctx->add_dist_error(ERROR('xact_fail'));
$ctx->add_dist_error(DISTERROR('xact_fail'));
}
}

Expand Down
Loading

0 comments on commit af03add

Please sign in to comment.