lucy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject Re: [lucy-user] Return value on error (add_index() and commit())
Date Fri, 16 Sep 2011 23:40:16 GMT
On Thu, Sep 15, 2011 at 03:28:13PM +0200, goran kent wrote:
> $indexer = Lucy::Index::Indexer->new(...) or die "ERROR...";
> $index->add_index(...) or die "ERROR...";
> $index->commit or die "ERROR...";
> ...which would really be ideal.
> I'm so used to coding with these kinds of checks in mind that not
> being able to do so is weird :)

If Indexer#commit returns without throwing an exception, Lucy believes that it
has succeeded.

> In fact, doing
> $index->add_index($idxpath) or die;
> ... will always die, even on success.
> Same with ->commit().
> Anyway, not a train-smash, just mentioning it.  The only way to check
> (sought of) for failure is with eval{}, which is not exactly elegant.

A lot happens during Indexer#commit() in a lot of subcomponents.  The call
stack is very deep.

If, theoretically, we were to establish an unbroken chain of reporting failure
from Indexer#commit all the way down into every last nook and cranny in the
library where something could go wrong, Lucy's source code would be a giant
mess.  In reality, such a scheme is not feasible.

If, instead, we were to return false for some subset of possible error
conditions, they you'd still need eval{} anyway to trap uncaught exceptions.

The impracticality of using return values to indicate failure in a large
library is one many reasons why Lucy usually prefers exceptions.

Another major rationale for Indexer#commit's current behavior is that throwing
an exception when something goes wrong is a failsafe default, while returning
false to indicate failure is not.


Marvin Humphrey

View raw message