[Koha-patches] [PATCH 2/2] Bug 5415 Let calls of SimpleSearch utilize considtent interface

Chris Nighswonger cnighswonger at foundations.edu
Thu Nov 18 18:05:42 CET 2010


On Thu, Nov 18, 2010 at 11:37 AM, Clay Fouts <cfouts at liblime.com> wrote:
> The die() in the above code is perfectly legitimate because the routine does
> not know how to handle the error gracefully.

I disagree. Rather than using a die(), take the time to code the
graceful error trapping. die() in most cases is the lazy way out,
imho.

> I cannot count the number of
> hours I've had to spend tracking a bug back to its source through all sorts
> of twists and turns because Koha did not die() when it couldn't figure out
> how to handle the original error and simply warn()ed about it or, more
> frequently, opted not to check for errors at all.

This is due more so to poor coding than anything else. Always handle
errors. If the coder can anticipate places in the code where errors
are likely to occur with enough accuracy to warrant a die() then there
is no reason not to go ahead and code graceful error trapping.

> The good thing about exceptions is that you cannot ignore the error and get
> away with it. Warn()s can and do get ignored, much to the detriment of
> developers, users, and everyone in between. Every best practices guide will
> tell you to die() as soon as you figure out that you can't accommodate the
> nature of the error, precisely because it is ugly and cannot be ignored,
> forcing the developer to handle it somehow at a higher level. Programmers
> are lazy.

Bingo! So we must fix our laziness and code proper error trapping. If
that means working back up the stake, so be it. Fix it right: fix it
once. Again, if the coder knows enough to put a die() they know enough
to write proper error trapping.

> Unless we compel ourselves to address errors, it's far too easy to
> ignore them, so we will (and do, if Koha's code is to serve as an example).
> Exceptions demand better coding practicing.

I agree with this in theory. However, what we must compel ourselves to
do is handle errors, not die().

> Koha already has a CGI-friendly die() handler with CGI::Carp. If how it is
> presented to the user is a concern, the template for that can be prettified.

Then this should be used and made to integrate in a more user-friendly
way with the rest of the Koha experience.

> Nevertheless, it's a favor to everyone not to let errors propagate
> throughout the system. It corrupts data and gives the false perception that
> everything is behaving correctly.

I don't see anything in this thread which would suggest that we "let
errors propagate throughout the system." On the contrary, the entire
thread seems to revolve around the best way to prevent that while
giving useful information to the user and maintaining maximum
availability of the rest of the system.

I tend to shy away from software that presents solid color screens
with cryptic information when it crashes... ;-)

Kind Regards,
Chris


More information about the Koha-patches mailing list