<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 15, 2014 at 7:11 PM, Sean Quinlan <span dir="ltr">&lt;<a href="mailto:spq.easy@gmail.com" target="_blank">spq.easy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Thanks!<div><br></div><div>I would have prefered to _not_ have to set unsafe, as it would be great if DBIC continued to handle exceptions internally as always, but just didn&#39;t pass the exception out after catching and handling it internally.<div><div><br></div><div>And I appreciate the &#39;<font face="arial, sans-serif"><span style="font-size:12.7272720336914px">architecturally unsound&#39; warning, and would agree in general. The only reason we&#39;re doing it this way is that we already have exception handling built in to the application. The idea here is not to just skip handling exceptions, but rather automate </span>propagating<span style="font-size:12.7272720336914px"> exceptions up to the application level, without having to hand-wrap all calls in eval. So if handle_error in DBI calls our applications add_error() (_without_ blocking or altering DBIC&#39;s), then the die on call is redundant, as the apps existing error handling will pick it up.</span></font></div></div></div></div></blockquote><div><br></div><div>I&#39;m really struggling to understand this reasoning, so forgive me if I come across as telling you that you&#39;re doing it all wrong...</div><div><br></div><div>Surely exceptions are always propagated up through the call stack to the nearest catch block and since DBIC does not catch exceptions for you, you are free to put a try/catch pair as high or as low in the call stack as you want. The whole point of structured exception handling is to let you put error handling where you want it instead of around every call that might possibly go wrong, no?</div><div><br></div><div>A try/catch pair in your dispatcher or entry point to your response handler should be a trivial thing to implement and would take care of meaningful responses in case of exceptions. Assuming no other try/catch pairs in the code path for a given request, that would still, of course, abort execution after the first error. But you want it to continue, right? Is that the crux of the matter?</div><div><br></div><div>I guess you have your reasons wanting to do that but I can think of any number of reasons (ranging from simply returning incorrect data to deleting the wrong data or worse) why this approach is dangerous. And I guess that&#39;s what Peter means by &quot;<span style="font-family:arial,sans-serif;font-size:13px">architecturally unsound&quot;...</span></div><div><br></div><div>Given a chunk of code that does multiple inserts/updates - do you really want it to just blindly continue, even after something has gone wrong?<br></div><div><br></div><div>I&#39;m curious about what sort of application would want that kind of unsafe-by-default behaviour...</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><font face="arial, sans-serif"><span style="font-size:12.7272720336914px"></span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.7272720336914px">Actually, if you wanted to encourage die or handle as an explicit decision and still discourage not handling it at all, perhaps a new optional argument to connect to provide a callback for external error handling, which when provided sets DBIC to not </span>propagate<span style="font-size:12.7272720336914px"> fatal errors to the application? exception_action seemed to come close, but was </span>triggered<span style="font-size:12.7272720336914px"> too often and did not suppress the die.</span></font></div></div></div></div></blockquote><div> </div><div>You probably know this already but in case you don&#39;t: With DBIC it&#39;s a relatively trivial thing to create your own base class for all resultsets and all result classes in your schema. In those two classes, overriding insert(), update() and a handful of other methods would probably get you what you want. It&#39;s of course more work than just flipping a switch in DBIC, but it&#39;s a lot less work than changing every place you call into DBIC. E.g. assuming a property on your schema that knows what to do with exceptions, something like:</div><div><br></div><div><div><div>sub update</div><div>{</div><div><span class="" style="white-space:pre">        </span>my $self = shift;</div><div><span class="" style="white-space:pre">        </span>return try {</div><div><span class="" style="white-space:pre">                </span>$self-&gt;next::method(@_);</div><div><span class="" style="white-space:pre">        </span>} catch {</div><div><span class="" style="white-space:pre">                </span>$self-&gt;result_source-&gt;schema-&gt;some_context_thingy-&gt;add_error($_);</div><div><span class="" style="white-space:pre">        </span>};</div><div>}</div></div></div><div><br></div><div>/L<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><span style="font-family:arial,sans-serif;font-size:12.7272720336914px">Please feel free to email me directly if there is anything I can do to help or questions I can answer. I&#39;d also of course be happy to test any updates.</span><br></div><div><font face="arial, sans-serif"><span style="font-size:12.7272720336914px"><br></span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.7272720336914px">-Cheers,</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.7272720336914px">Sean</span></font></div></div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 15, 2014 at 12:01 PM, Peter Rabbitson <span dir="ltr">&lt;<a href="mailto:rabbit+dbic@rabbit.us" target="_blank">rabbit+dbic@rabbit.us</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>On 10/15/2014 04:55 PM, Sean Quinlan wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The end result I want is to not have to wrap every update / insert / etc<br>
with an eval.<br>
<br>
I have no problem if DBIC internals use exception-based control<br>
internally. I just want to optionally have it not bubble up to the level<br>
of my application. It would be far more elegant if I could have DBIC<br>
play nicely with our applications exception handling, rather than have<br>
to insulate every usage manually.<br>
<br>
</blockquote>
<br></span>
This is a reasonable (albeit architecturally unsound) request. If the &#39;unsafe&#39; handling is requested everything not happening in a transaction should indeed not result in exceptions.<br>
<br>
In order to go forward with this I will need a modest set of lives_ok checks for various operations. The actual implementation will be more involved and will likely be carried out by me or another core contrib. For a concise test example, take a look at<br>
<a href="https://github.com/dbsrgits/dbix-class/blob/current/for_cpan_index/t/schema/anon.t" target="_blank">https://github.com/dbsrgits/<u></u>dbix-class/blob/current/for_<u></u>cpan_index/t/schema/anon.t</a><br>
<br>
Let me know if you have any further questions<br>
<br>
Cheers!<div><div><br>
<br>
______________________________<u></u>_________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-<u></u>bin/mailman/listinfo/dbix-<u></u>class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/<u></u>repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/<u></u>dbix-class@lists.scsys.co.uk</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a><br></blockquote></div><br></div></div>