[Dbix-class] Proper way to suppress die from DBIx::Class

Lasse Makholm lasse at unity3d.com
Wed Oct 15 22:46:39 GMT 2014


On Wed, Oct 15, 2014 at 7:11 PM, Sean Quinlan <spq.easy at gmail.com> wrote:

> Thanks!
>
> 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't
> pass the exception out after catching and handling it internally.
>
> And I appreciate the 'architecturally unsound' warning, and would agree
> in general. The only reason we'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 propagating 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's), then the die on call is redundant, as the
> apps existing error handling will pick it up.
>
> 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 propagate fatal errors to the
> application? exception_action seemed to come close, but was triggered too
> often and did not suppress the die.
>

Thinking about this, something like an internal_exception_action and an
external_exception_action might be a useful distinction. The current
behaviour of (internal) exception_action is useful because it allows us to
capture the full amount of information about the origin of errors (stack,
args, etc...) and use custom exception classes but is, as Sean points out,
ill-suited for making errors non-fatal.

An external_exception_behaviour, on the other hand, would be useful for
facilitating application defined error behaviour. Especially if the return
value of such a hook would propagate back out to the caller of the failed
DBIC method. Think:

In schema class:

__PACKAGE__->external_exception_action(sub { return
MyApp::DBICError->new(@_) });

Elsewhere:

my $rs = $rsrc->search(....);
my @results = $rs->isa('MyApp::DBICError') ? () : $rs->all;

/L

Please feel free to email me directly if there is anything I can do to help
> or questions I can answer. I'd also of course be happy to test any updates.
>
> -Cheers,
> Sean
>
> On Wed, Oct 15, 2014 at 12:01 PM, Peter Rabbitson <rabbit+dbic at rabbit.us>
> wrote:
>
>> On 10/15/2014 04:55 PM, Sean Quinlan wrote:
>>
>>> The end result I want is to not have to wrap every update / insert / etc
>>> with an eval.
>>>
>>> I have no problem if DBIC internals use exception-based control
>>> internally. I just want to optionally have it not bubble up to the level
>>> of my application. It would be far more elegant if I could have DBIC
>>> play nicely with our applications exception handling, rather than have
>>> to insulate every usage manually.
>>>
>>>
>> This is a reasonable (albeit architecturally unsound) request. If the
>> 'unsafe' handling is requested everything not happening in a transaction
>> should indeed not result in exceptions.
>>
>> 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
>> https://github.com/dbsrgits/dbix-class/blob/current/for_
>> cpan_index/t/schema/anon.t
>>
>> Let me know if you have any further questions
>>
>> Cheers!
>>
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/
>> dbix-class at lists.scsys.co.uk
>>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20141016/91f3f7c7/attachment.htm>


More information about the DBIx-Class mailing list