CC: | bug-test-exception [...] rt.cpan.org, timb [...] cpan.org |
Subject: | Re: Fails to Catch Certain DBI Exceptions |
Date: | Tue, 14 Mar 2006 09:39:52 +0000 |
To: | "David E. Wheeler" <dwheeler [...] cpan.org> |
From: | Tim Bunce <Tim.Bunce [...] pobox.com> |
Is RaiseError enabled?
Tim.
On Tue, Feb 21, 2006 at 10:24:30PM -0800, David E. Wheeler wrote:
Show quoted text
> Some DBI exceptions are not properly caught by Test::Exception. For
> example, this script:
>
> use strict;
> use Test::More tests => 1;
> use Test::Exception;
> use DBI;
>
> dies_ok { DBI->connect('dbi:Pg:dbname=ick', 'postgres', '') }
> 'DBI should die with bogus values';
>
> When I run it, I get:
>
> 1..1
> DBI connect('dbname=ick','postgres',...) failed: FATAL: database
> "ick" does not exist
> at /usr/local/lib/perl5/site_perl/5.8.7/Test/Exception.pm line 128
> not ok 1 - DBI should die with bogus values
> # Failed test 'DBI should die with bogus values'
> # in /Users/david/bin/try at line 9.
> # Looks like you failed 1 test of 1.
>
> That's not what I expect, of course. The problem doesn't exist for
> all DBI exceptions, though. If I change the DSN to just 'foo',
> dies_ok will catch it. But when I have a correct DSN and database
> username and password, DBD::Pg that generates the exception (using
> DBI's exception-handling C function, I believe), and then
> Test::Exception doesn't catch it.
>
> This is not local to DBD::Pg. If I change the test to use SQLite:
>
> dies_ok { DBI->connect('dbi:SQLite:dbname=/root/foo', '', '') }
> 'DBI should die with bogus values';
>
> Then I get the same problem:
>
> 1..1
> DBI connect('dbname=/root/foo','',...) failed: unable to open
> database file(1) at dbdimp.c line 94 at /usr/local/lib/perl5/
> site_perl/5.8.7/Test/Exception.pm line 128
> not ok 1 - DBI should die with bogus values
> # Failed test 'DBI should die with bogus values'
> # in /Users/david/bin/try at line 10.
> # Looks like you failed 1 test of 1.
>
> I'm Cc'ing Tim on this in case he has some suggestions as to what
> might be different about exceptions thrown by the DBI.
>
> Thanks!
>
> David