Skip to content

Commit af03add

Browse files
committed
xxx package errors
1 parent cff0645 commit af03add

File tree

9 files changed

+235
-136
lines changed

9 files changed

+235
-136
lines changed

lib/PAUSE/Indexer/Context.pm

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,92 @@ sub add_package_warning {
2828
text => $warning,
2929
};
3030

31+
$Logger->log([
32+
"adding package warning to %s: %s",
33+
$package_obj->{PACKAGE},
34+
$list->[-1],
35+
]);
36+
37+
return;
38+
}
39+
40+
has package_status => (
41+
is => 'bare',
42+
reader => '_package_status',
43+
default => sub { {} },
44+
);
45+
46+
sub _set_package_error {
47+
my ($self, $package_obj, $status) = @_;
48+
49+
# XXX remove this block when ->index_status is dead
50+
$package_obj->{FIO}{DIO}->index_status(
51+
$self,
52+
$package_obj->{PACKAGE},
53+
$package_obj->{PP}{version},
54+
$package_obj->{PP}{infile},
55+
2, # OK
56+
$status->{header},
57+
);
58+
59+
$self->_package_status->{ $package_obj->{PACKAGE} } = {
60+
is_success => 0,
61+
filename => $package_obj->{PP}{infile},
62+
version => $package_obj->{PP}{version},
63+
header => $status->{header},
64+
body => $status->{body},
65+
};
66+
67+
$Logger->log([
68+
"set error status for %s",
69+
$package_obj->{PACKAGE},
70+
]);
71+
3172
return;
3273
}
3374

75+
sub record_package_indexing {
76+
my ($self, $package_obj) = @_;
77+
78+
# XXX remove this block when ->index_status is dead
79+
$package_obj->{FIO}{DIO}->index_status(
80+
$self,
81+
$package_obj->{PACKAGE},
82+
$package_obj->{PP}{version},
83+
$package_obj->{PP}{infile},
84+
1, # OK
85+
"it worked",
86+
);
87+
88+
$self->_package_status->{ $package_obj->{PACKAGE} } = {
89+
is_success => 1,
90+
filename => $package_obj->{PP}{infile},
91+
version => $package_obj->{PP}{version},
92+
header => "package indexed successfully",
93+
body => "the package was indexed successfully",
94+
};
95+
96+
$Logger->log([
97+
"set OK status for %s",
98+
$package_obj->{PACKAGE},
99+
]);
100+
101+
return;
102+
}
103+
104+
sub abort_indexing_package {
105+
my ($self, $package_obj, $error) = @_;
106+
107+
$Logger->log("abort indexing $package_obj->{PACKAGE}");
108+
109+
$self->_set_package_error($package_obj, $error);
110+
111+
die PAUSE::Indexer::Abort::Package->new({
112+
message => $error->{header},
113+
public => 1,
114+
});
115+
}
116+
34117
sub warnings_for_all_packages {
35118
my ($self) = @_;
36119

lib/PAUSE/Indexer/Errors.pm

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,22 @@ use v5.12.0;
33
use warnings;
44

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

10-
my %ERROR;
10+
sub dist_error;
11+
sub pkg_error;
1112

12-
sub public_error {
13-
my ($name, $arg) = @_;
14-
$ERROR{$name} = {
15-
ident => $name,
16-
public => 1,
17-
%$arg,
18-
};
19-
}
20-
21-
public_error blib => {
13+
dist_error blib => {
2214
header => 'archive contains a "blib" directory',
2315
body => <<'EOF'
2416
The distribution contains a blib/ directory and is therefore not being indexed.
2517
Hint: try 'make dist'.
2618
EOF
2719
};
2820

29-
public_error multiroot => {
21+
dist_error multiroot => {
3022
header => 'archive has multiple roots',
3123
body => sub {
3224
my ($dist) = @_;
@@ -38,7 +30,7 @@ EOF
3830
},
3931
};
4032

41-
public_error no_distname_permission => {
33+
dist_error no_distname_permission => {
4234
header => 'missing permissions on distname package',
4335
body => sub {
4436
my ($dist) = @_;
@@ -57,7 +49,7 @@ EOF
5749
},
5850
};
5951

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

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

78-
public_error unstable_release => {
70+
dist_error unstable_release => {
7971
header => 'META release_status is not stable',
8072
body => <<'EOF',
8173
Your META file provides a release status other than "stable", so this
8274
distribution will not be indexed.
8375
EOF
8476
};
8577

86-
public_error worldwritable => {
78+
dist_error worldwritable => {
8779
header => 'archive has world writable files',
8880
body => sub {
8981
my ($dist) = @_;
@@ -95,29 +87,110 @@ EOF
9587
},
9688
};
9789

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

106-
sub ERROR {
98+
pkg_error bad_package_name => {
99+
header => 'Not indexed because of invalid package name.',
100+
body => <<'EOF',
101+
This package wasn't indexed because its name doesn't conform to standard
102+
naming. Basically: one or more valid identifiers, separated by double colons
103+
(::).
104+
EOF
105+
};
106+
107+
pkg_error no_permission => {
108+
header => 'Not indexed because the required permissions were missing.',
109+
body => <<'EOF',
110+
This package wasn't indexed because you don't have permission to use this
111+
package name. Hint: you can always find the legitimate maintainer(s) on PAUSE
112+
under "View Permissions".
113+
EOF
114+
};
115+
116+
pkg_error version_openerr => {
117+
header => 'Not indexed because of version handling error.',
118+
body => <<'EOF',
119+
The PAUSE indexer was not able to read the file.
120+
EOF
121+
};
122+
123+
pkg_error version_parse => {
124+
header => 'Not indexed because of version parsing error.',
125+
body => <<'EOF',
126+
The PAUSE indexer was not able to parse the file.
127+
128+
Note: the indexer is running in a Safe compartement and cannot provide the full
129+
functionality of perl in the VERSION line. It is trying hard, but sometime it
130+
fails. As a workaround, please consider writing a META.yml that contains a
131+
"provides" attribute, or contact the CPAN admins to investigate (yet another)
132+
workaround against "Safe" limitations.
133+
EOF
134+
};
135+
136+
pkg_error version_too_long => {
137+
header => 'Not indexed because the version string was too long.',
138+
body => <<'EOF',
139+
The maximum length of a version string is 16 bytes, which is already quite
140+
long. Please consider picking a shorter version.
141+
EOF
142+
};
143+
144+
pkg_error wtf => {
145+
header => 'Not indexed: something surprising happened.',
146+
body => <<'EOF',
147+
The PAUSE indexer couldn't index this package. It ended up with a weird
148+
internal state, like thinking your package name was empty or your version was
149+
undefined. If you see this, you should probably contact the PAUSE admins.
150+
EOF
151+
};
152+
153+
my %DIST_ERROR;
154+
my %PKG_ERROR;
155+
156+
sub DISTERROR {
157+
my ($ident) = @_;
158+
159+
my $error = $DIST_ERROR{$ident};
160+
unless ($error) {
161+
Carp::confess("requested unknown distribution error: $ident");
162+
}
163+
164+
return $error;
165+
}
166+
167+
sub PKGERROR {
107168
my ($ident) = @_;
108169

109-
my $error = PAUSE::Indexer::Errors->error_named($ident);
170+
my $error = $PKG_ERROR{$ident};
110171
unless ($error) {
111-
Carp::confess("requested unknown error: $ident");
172+
Carp::confess("requested unknown package error: $ident");
112173
}
113174

114175
return $error;
115176
}
116177

117-
sub error_named {
118-
my ($self, $ident) = @_;
178+
sub dist_error {
179+
my ($name, $arg) = @_;
180+
$DIST_ERROR{$name} = {
181+
ident => $name,
182+
public => 1,
183+
%$arg,
184+
};
185+
}
119186

120-
return $ERROR{$ident};
187+
sub pkg_error {
188+
my ($name, $arg) = @_;
189+
$PKG_ERROR{$name} = {
190+
ident => $name,
191+
public => 1,
192+
%$arg,
193+
};
121194
}
122195

123196
1;

lib/PAUSE/dist.pm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ sub examine_dist {
298298
}
299299
} elsif ($dist =~ /\.pm\.(?:Z|gz|bz2)$/) {
300300
$self->{SUFFIX} = "N/A";
301-
$ctx->abort_indexing_dist(ERROR('single_pm'));
301+
$ctx->abort_indexing_dist(DISTERROR('single_pm'));
302302
} elsif ($dist =~ /\.zip$/) {
303303
$self->{SUFFIX} = "zip";
304304
my $unzipbin = $self->hub->{UNZIPBIN};
@@ -573,7 +573,7 @@ sub check_blib {
573573
my ($self, $ctx) = @_;
574574
if (grep m|^[^/]+/blib/|, @{$self->{MANIFOUND}}) {
575575
$self->{HAS_BLIB}++;
576-
$ctx->abort_indexing_dist(ERROR('blib'));
576+
$ctx->abort_indexing_dist(DISTERROR('blib'));
577577
}
578578
# sometimes they package their stuff deep inside a hierarchy
579579
my @found = @{$self->{MANIFOUND}};
@@ -598,7 +598,7 @@ sub check_blib {
598598
# more than one entry in this directory means final check
599599
if (grep m|^blib/|, @found) {
600600
$self->{HAS_BLIB}++;
601-
$ctx->abort_indexing_dist(ERROR('blib'));
601+
$ctx->abort_indexing_dist(DISTERROR('blib'));
602602
}
603603
last DIRDOWN;
604604
}
@@ -610,7 +610,7 @@ sub check_multiple_root {
610610
my @top = grep { s|/.*||; !$seen{$_}++ } map { $_ } @{$self->{MANIFOUND}};
611611
if (@top > 1) {
612612
$self->{HAS_MULTIPLE_ROOT} = \@top;
613-
$ctx->abort_indexing_dist(ERROR('multiroot'));
613+
$ctx->abort_indexing_dist(DISTERROR('multiroot'));
614614
} else {
615615
$self->{DISTROOT} = $top[0];
616616
}
@@ -633,7 +633,7 @@ sub check_world_writable {
633633

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

639639
sub filter_pms {
@@ -827,6 +827,7 @@ sub examine_pms {
827827
}
828828

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

922923
unless ($json || $yaml) {
923924
$self->{METAFILE} = "No META.yml or META.json found";
924-
$ctx->abort_indexing_dist(ERROR('no_meta'));
925+
$ctx->abort_indexing_dist(DISTERROR('no_meta'));
925926
return;
926927
}
927928

@@ -971,7 +972,7 @@ sub check_indexability {
971972

972973
if (($self->{META_CONTENT}{release_status} // 'stable') ne 'stable') {
973974
# META.json / META.yml declares it's not stable; do not index!
974-
$ctx->abort_indexing_dist(ERROR('unstable_release'));
975+
$ctx->abort_indexing_dist(DISTERROR('unstable_release'));
975976
return;
976977
}
977978
}

lib/PAUSE/mldistwatch.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ sub _do_the_database_work {
370370
my $main_pkg = $dio->_package_governing_permission;
371371

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

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

0 commit comments

Comments
 (0)