<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">El mié., 14 sept. 2016 a las 4:58, Jonathan Druart (<<a href="mailto:jonathan.druart@bugs.koha-community.org">jonathan.druart@bugs.koha-community.org</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
We used to have problems with transactions, if they were used from the<br>
a subroutine/method which was called from tests (which use<br>
transactions as well), it did not work.<br>
Two transactions could not be started together.<br></blockquote><div><br></div><div>I recall nested transactions were problematic.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now that we are using DBIx::Class transactions it works correctly and<br>
we will be able to use it in the codebase everywhere we need it.<br>
I try to use it as soon as it's useful (see<br>
Koha::Acquisition::Currency->store and bug 16907<br>
Koha::Patrons->delete).<br></blockquote><div><br></div><div>Yes! The point of my email, was to highlight the possibility we now have, and gather opinions on how to better do it. I wanted to raise this on a dev meeting. We have a tradition of letting patches speak, but some healthy discussion about this could let us reach some consensus, and guide new devs into good coding practices.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Regarding the try-catch module, the following is fine by me:<br>
use Koha::Exceptions;<br>
use Try::Tiny;<br>
sub boom {<br>
    Koha::Exceptions::Exception->throw;<br>
}<br>
try {<br>
    boom();<br>
} catch {<br>
    if ( ref($_) eq 'Koha::Exceptions::Exception' ) {<br>
        # Do that<br>
    } elsif ( ref($_) eq 'Koha::Exceptions::AnotherException' ) {<br>
        # do something else<br>
    }<br>
}<br></blockquote><div><br></div><div>Yes, I like the Try::Tiny lib and would propose to just start using it. Your code is simple to read, and a clear improvement! Koha::Virtualshelf already raises exceptions and <a href="http://shelves.pl">shelves.pl</a> catches them on another way, in master!</div><div>I mentioned TryCatch only because its syntax is sexier IMHO, but the main point was, again, to highlight the possible use of some convenient try/catch lib on the Koha:: namespace, which in conjuntcion with transactions would make our code quite reliable and readable.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You should also have a look at Bug 13995 - Proper Exception handling<br></blockquote><div><br></div><div>I will, I recall the bug got stuck because Olli introduced one file per exception. It is handy for editor's autocomplete features, but it looked awkward. That's why I propose splitting exceptions files on a per-package basis.</div><div> </div><div>Cheers </div></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(117,117,117);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:12.8px">Tomás Cohen Arazi</div><div style="color:rgb(117,117,117);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:12.8px">Theke Solutions (<a href="http://theke.io/">https://theke.io</a>)<br>✆ +54 9351 3513384<br>GPG: B2F3C15F</div></div></div>