<div dir="ltr"><div>Hi Barton,</div><div><br></div><div>Yes, and no. It depends.</div><div><br></div><div>Example 1)<br></div><div>  my $biblio_to_edit = Koha::Biblios->find( $query->param('biblionumber') );</div><div>  say sprintf "you are editing %s", $biblio_to_edit->title;</div><div>Here we need to display a message if the biblio you want to edit does no longer exist (or invalid id).</div><div><br></div><div>Example 2)</div><div>  sub one_more_sub {</div><div>    my ( $itemnumber ) = @_;<br></div><div>    my $item = Koha::Items->find( $itemnumber );</div><div>    return unless $item;</div><div>    say $item->homebranch->branchname;</div><div>    say Koha::Frameworks->find($item->biblio->frameworkcode);</div><div>  }</div><div>Here we do not need to make sure the homebranch or the biblio or the framework exist. The DB constraints take care of that for us. If the itemnumber exists, other objects exist.<br></div><div><br></div><div><br></div><div>In that case of 1) we should stop the process at that point if the biblio does not exist, no need to continue.</div><div>On bug 18403 I have introduced a way to do that, it is as much useful as ugly. We wanted to display a message if 1. the borrowernumber does not exist, or 2. the logged-in patron does not have the permission to view patron's info for a given borrowernumber. It looks like:</div><div><br></div><div>  my $logged_in_user = Koha::Patrons->find( $loggedinuser )</div><div>                                     or die "Not logged in";<br>  output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );<br><br></div><div>What does it do? It dies in case $logged_in_user does not exist (it should *never* happen, but... who really knows?)</div><div>And will render the template by setting an error flag "unknown_patron" or "cannot_see_patron_infos" if needed (for more info, see C4::Output::output_and_exit_if_error and blocking_errors.inc).<br></div><div><br></div><div>Basically, we should avoid indentation blocks (if ( defined $item ) { # then continue }), it is usually a bad idea.<br></div><div><br></div><div>See also:</div><div><div class="inbox-inbox-knob-buttons">
      </div>
     <a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20661"><b>Bug 20661</b></a> <span id="inbox-inbox-summary_container">
      - <span id="inbox-inbox-short_desc_nonedit_display">Implement blocking errors for circulation scripts</span><br></span></div><div><div class="inbox-inbox-knob-buttons">
      </div>
     <a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20351"><b>Bug 20351</b></a> <span id="inbox-inbox-summary_container">
      - <span id="inbox-inbox-short_desc_nonedit_display">Implement blocking errors for serials scripts</span></span><span id="inbox-inbox-summary_container"></span></div><div>Help me to make them in, and I will implement more.</div><div><br></div><div>Going further, see a previous discussion "Expected behaviour if itemtype does not exist" - <a href="http://lists.koha-community.org/pipermail/koha-devel/2017-August/043924.html">http://lists.koha-community.org/pipermail/koha-devel/2017-August/043924.html</a><br></div><div><br></div><div>Cheers,</div><div>Jonathan<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 13 Jun 2018 at 14:23 Barton Chittenden <<a href="mailto:barton@bywatersolutions.com">barton@bywatersolutions.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Calling a method or accessing a member of an undefined object will throw a fatal error that looks like this:  "can't call method * on an undefined value at ..."</div><div><br></div><div>For example, this code will cause a software error if $data->{itemnumber} exists, but the item doesn't exist (maybe it's been deleted?):<br></div><div><br></div><div>my $item = Koha::Items->find( $data->{itemnumber} );</div><div>my $biblio = $item->biblio;</div><div><br></div><div>How this is handled will of course depend on context -- maybe we should carp and continue, or maybe just</div><div><br></div><div><div>my $item = Koha::Items->find( $data->{itemnumber} );</div><div>my $biblio = $item->biblio if defined $item;</div></div><div><br></div><div>I would like to add a coding standard that we always check for this.</div><div><br></div><div>Thanks,</div><div><br></div><div>--Barton</div></div>
_______________________________________________<br>
Koha-devel mailing list<br>
<a href="mailto:Koha-devel@lists.koha-community.org" target="_blank">Koha-devel@lists.koha-community.org</a><br>
<a href="http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel" rel="noreferrer" target="_blank">http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel</a><br>
website : <a href="http://www.koha-community.org/" rel="noreferrer" target="_blank">http://www.koha-community.org/</a><br>
git : <a href="http://git.koha-community.org/" rel="noreferrer" target="_blank">http://git.koha-community.org/</a><br>
bugs : <a href="http://bugs.koha-community.org/" rel="noreferrer" target="_blank">http://bugs.koha-community.org/</a></blockquote></div></div>