Skip to content
Browse files

[delivers #16029551] COinS calculator dying on unchecked return value

If, as in the case of a newly deleted title, an OPAC search result list
includes a title that no longer exists, the COinS creator would die
from accessing an unchecked return value. This patch explicitly croaks
in that case and places catch()es within the caller to emit a simple
warn instead of dying.
  • Loading branch information...
1 parent 8d811a9 commit e47936293325cb9252f586079988e807bd05f4ce @ctfliblime ctfliblime committed Jul 27, 2011
Showing with 28 additions and 13 deletions.
  1. +2 −1 C4/Biblio.pm
  2. +8 −7 C4/VirtualShelves/Page.pm
  3. +10 −4 opac/opac-detail.pl
  4. +8 −1 opac/opac-search.pl
View
3 C4/Biblio.pm
@@ -19,7 +19,7 @@ package C4::Biblio;
use strict;
use warnings;
-# use utf8;
+use Carp;
use MARC::Record;
use MARC::File::USMARC;
use MARC::File::XML;
@@ -1066,6 +1066,7 @@ Returns the COinS(a span) which can be included in a biblio record
sub GetCOinSBiblio {
my ( $biblionumber ) = @_;
my $record = GetMarcBiblio($biblionumber);
+ croak "Unable to find record ($biblionumber)" if !$record;
# get the coin format
my $pos7 = substr $record->leader(), 7,1;
View
15 C4/VirtualShelves/Page.pm
@@ -203,13 +203,14 @@ SWITCH: {
}
($items, $totitems) = GetShelfContents($shelfnumber, $shelflimit, $shelfoffset);
for my $this_item (@$items) {
- # the virtualshelfcontents table does not store these columns nor are they retrieved from the items
- # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn
- #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'};
- #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'};
- $this_item->{'dateadded'} = format_date($this_item->{'dateadded'});
- $this_item->{'imageurl'} = getitemtypeinfo($this_item->{'itemtype'})->{'imageurl'};
- $this_item->{'coins'} = GetCOinSBiblio($this_item->{'biblionumber'});
+ # the virtualshelfcontents table does not store these columns nor are they retrieved from the items
+ # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn
+ #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'};
+ #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'};
+ $this_item->{dateadded} = format_date($this_item->{dateadded});
+ $this_item->{imageurl} = getitemtypeinfo($this_item->{itemtype})->{imageurl};
+ $this_item->{coins} = try{GetCOinSBiblio($this_item->{biblionumber})} catch {warn $_; undef};
+ warn "ASDFASDFASDFASDF";
}
push @paramsloop, {display => 'privateshelves'} if $category == 1;
$showadd = 1;
View
14 opac/opac-detail.pl
@@ -20,7 +20,7 @@
use strict;
use warnings;
-
+use Try::Tiny;
use CGI;
use C4::Auth;
use C4::Branch;
@@ -270,9 +270,15 @@ BEGIN
);
# COinS format FIXME: for books Only
-$template->param(
- ocoins => GetCOinSBiblio($biblionumber),
-);
+my $coins = try {
+ return GetCOinSBiblio($_->{biblionumber})
+}
+catch {
+ warn $_;
+ return undef;
+};
+
+$template->param(ocoins => $coins);
my $loggedincommenter;
my $reviews;
View
9 opac/opac-search.pl
@@ -7,6 +7,7 @@
# to perform, etc.
## load Koha modules
use Koha;
+use Try::Tiny;
use C4::Context;
use C4::Output;
use C4::Auth qw(:DEFAULT get_session);
@@ -512,7 +513,13 @@ ($)
}
}
foreach (@newresults) {
- $_->{coins} = GetCOinSBiblio($_->{'biblionumber'});
+ $_->{coins} = try {
+ return GetCOinSBiblio($_->{biblionumber})
+ }
+ catch {
+ warn $_;
+ return undef;
+ };
}
if ($results_hashref->{$server}->{"hits"}){

0 comments on commit e479362

Please sign in to comment.
Something went wrong with that request. Please try again.