on_error issue with AnyEvent::DBI
Marc Lehmann
schmorp at schmorp.de
Sat Feb 1 21:55:58 CET 2020
On Sat, Feb 01, 2020 at 08:50:18PM +0100, Winfried Neessen <wn at neessen.net> wrote:
> I am currently trying to implement AnyEvent::DBI into the code I am writing. While intentionally providing wrong
Hi!
> connection data to my PgSQL database, to test the on_error behaviour I ran into an issue. The provided on_error
> callback is not executed, as the _error method in AnyEvent/DBI.pm dies before the actual call of the self provided
> callback is issues. I narrowed the issue down to line 349 of DBI.pm:
>
> 346 # for fatal errors call all enqueued callbacks with error
> 347 while (my $req = shift @{$self->{queue}}) {
> 348 local $@ = $error;
> 349 $req->[0]->($self);
> 350 }
>
> Once the $req->[0]->($self); is executed, the "die" of the DBI->connect() will be executed and the script will not
Which die, the die from this line:
$DBH = DBI->connect ($dbi, $user, $pass, \%attr) or die $DBI::errstr;
I am not sure I can follow you, for example, you say the _error method
dies, but how do you know this and what message does it die with (this
information is crucial) - do you have a test case that shows the problem
maybe?
I made a trivial testcase myself:
use AE;
use AnyEvent::DBI;
my $dbh = new AnyEvent::DBI "DBI:error:ex", "", "",
on_error => sub {
warn "hiya<@_><$@>\n";#d#
1
};
AE::cv->recv;
And this results in:
hiya<AnyEvent::DBI=HASH(0x55555598c4a8) ./tst2 10 1><install_driver(error) failed: C...
So on_error for connect works for me.
> Any idea why this is happening? I really need to my own on_error, as I don't want my AnyEvent loop to
> die just because the DB might not be available or the connection string might be not correct.
Well, it seems to work fine for me, but I don't understand your
explanation at all - if I had to guess, I would say most likely the
problem is somewhere in code you haven't shown me, such as in some request
callback that dies (i.e. a die in your code which you wouid have to catch
and handle yourself).
The easiest way to proceed would be to create a small testcase that shows
the problem.
Greetings,
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list