@@ -10,6 +10,16 @@ use Sub::Exporter -setup => {
1010sub dist_error ;
1111sub pkg_error ;
1212
13+ sub _assert_args_present {
14+ my ($ident , $hash , $names_demanded ) = @_ ;
15+
16+ for my $name (@$names_demanded ) {
17+ next if exists $hash -> {$name };
18+
19+ Carp::confess(" no $name given in PKGERROR($ident )" )
20+ }
21+ }
22+
1323dist_error blib => {
1424 header => ' archive contains a "blib" directory' ,
1525 body => <<'EOF'
@@ -105,16 +115,23 @@ EOF
105115};
106116
107117pkg_error db_conflict => {
108- # TODO bring back $package
109118 header => " Not indexed because of conflicting record in index" ,
110- body => <<"EOF"
111- Indexing failed because of conflicting records for \$ package. Please report
112- the case to the PAUSE admins at modules\@ perl.org.
119+ body => sub {
120+ my ($arg ) = @_ ;
121+
122+ _assert_args_present(db_conflict => $arg , [ qw( package_name) ]);
123+
124+ return <<"EOF"
125+ Indexing failed because of conflicting records for $arg ->{package_name}.
126+ Please report the case to the PAUSE admins at modules\@ perl.org.
113127EOF
128+ },
114129};
115130
116131pkg_error db_error => {
117- # TODO bring back db error string? seems weird -- rjbs, 2023-05-01
132+ # Before PKGERROR existed, this would include the database error. This felt
133+ # like a bad idea to rjbs when he refactored, so he removed it. Easy to
134+ # re-add, if we want to, though! -- rjbs, 2023-05-03
118135 header => ' Not indexed because of database error' ,
119136 body => <<'EOF' ,
120137The PAUSE indexer could not store the indexing result in the PAUSE database due
@@ -124,30 +141,48 @@ EOF
124141};
125142
126143pkg_error dual_newer => {
127- # TODO bring back parameters
128144 header => ' Not indexed because of an newer dual-life module' ,
129- body => <<'EOF' ,
130- Not indexed because package $opack in file $ofile has a dual life in $odist.
131- The other version is at $oldversion, so not indexing seems okay.
145+ body => sub {
146+ my ($old ) = @_ ;
147+
148+ _assert_args_present(db_conflict => $old , [ qw( package file dist version) ]);
149+
150+ return <<"EOF" ;
151+ Not indexed because package $old ->{pack} in file $old ->{file} has a dual life
152+ in $old ->{dist}. The other version is at $old ->{version}, so not indexing
153+ seems okay.
132154EOF
155+ },
133156};
134157
135158pkg_error dual_older => {
136- # TODO bring back parameters
137159 header => ' Not indexed because of an older dual-life module' ,
138- body => <<'EOF' ,
139- Not indexed because package $opack in file $ofile seems to have a dual life in
140- $odist. Although the other package is at version [$oldversion], the indexer
141- lets the other dist continue to be the reference version, shadowing the one in
142- the core. Maybe harmless, maybe needs resolving.
160+ body => sub {
161+ my ($old ) = @_ ;
162+
163+ _assert_args_present(db_conflict => $old , [ qw( package file dist version) ]);
164+
165+ return <<"EOF" ;
166+ Not indexed because package $old ->{pack} in file $old ->{file} seems to have a
167+ dual life in $old ->{dist}. Although the other package is at version
168+ [$old ->{version}], the indexer lets the other dist continue to be the reference
169+ version, shadowing the one in the core. Maybe harmless, maybe needs resolving.
143170EOF
171+ }
144172};
145173
146174pkg_error mtime_fell => {
147- # TODO bring back ofile/odist in body
148175 header => ' Release seems outdated' ,
149- body => q{ Not indexed because $ofile in $odist also has a zero version
150- number and the distro has a more recent modification time.} ,
176+ body => sub {
177+ my ($old ) = @_ ;
178+
179+ _assert_args_present(db_conflict => $old , [ qw( package file dist version) ]);
180+
181+ return <<"EOF" ;
182+ Not indexed because $old ->{file} in $old ->{dist} also has a zero version number
183+ and the distro has a more recent modification time.
184+ EOF
185+ }
151186};
152187
153188pkg_error no_permission => {
@@ -160,17 +195,33 @@ EOF
160195};
161196
162197pkg_error version_fell => {
163- # TODO bring back "file in $dist", make the q{...} a qq{...}
164198 header => " Not indexed because of decreasing version number" ,
165- body => q{ Not indexed because $ofile in $odist has a higher version number
166- ($oldversion)} ,
199+ body => sub {
200+ my ($old ) = @_ ;
201+
202+ _assert_args_present(db_conflict => $old , [ qw( package file dist version) ]);
203+
204+ return <<"EOF" ;
205+ Not indexed because $old ->{file} in $old ->{dist} has a higher version number
206+ ($old ->{version})
207+ EOF
208+ }
167209};
168210
169211pkg_error version_invalid => {
170- # TODO put back $version itself? It's already in the report.
171- # -- rjbs, 2023-05-01
172212 header => ' Not indexed because version is not a valid "lax version" string.' ,
173- body => undef ,
213+ body => sub {
214+ my ($arg ) = @_ ;
215+
216+ _assert_args_present(db_conflict => $arg , [ qw( version) ]);
217+
218+ return <<"EOF" ;
219+ The version present in the file, "$arg ->{version}", is not a valid lax version
220+ string. You can read more in "perldoc version". This restriction would be
221+ enforced at compile time if you put your version string within your package
222+ declaration.
223+ EOF
224+ }
174225};
175226
176227pkg_error version_openerr => {
@@ -225,18 +276,27 @@ sub DISTERROR {
225276}
226277
227278sub PKGERROR {
228- my ($ident ) = @_ ;
279+ my ($ident , $arg ) = @_ ;
229280
230- my $error = $PKG_ERROR {$ident };
231- unless ($error ) {
281+ my $template = { $PKG_ERROR {$ident }-> %* };
282+
283+ unless ($template ) {
232284 Carp::confess(" requested unknown package error: $ident " );
233285 }
234286
287+ my $error = { %$template };
288+
289+ if (ref $error -> {body }) {
290+ my $body = $error -> {body }-> ($arg );
291+ $error -> {body } = $body ;
292+ }
293+
235294 return $error ;
236295}
237296
238297sub dist_error {
239298 my ($name , $arg ) = @_ ;
299+
240300 $DIST_ERROR {$name } = {
241301 ident => $name ,
242302 public => 1,
@@ -246,6 +306,7 @@ sub dist_error {
246306
247307sub pkg_error {
248308 my ($name , $arg ) = @_ ;
309+
249310 $PKG_ERROR {$name } = {
250311 ident => $name ,
251312 public => 1,
0 commit comments