bigpresh / Dancer-Plugin-Database

Dancer::Plugin::Database - easy database support for Dancer applications
http://search.cpan.org/dist/Dancer-Plugin-Database
37 stars 36 forks source link

If MySQL is not started I get confusing error message. #7

Closed NickHibma closed 13 years ago

NickHibma commented 13 years ago
[5966]  core 0.007483> [hit 11]entering before hook in /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Route/Registry.pm l. 50
[5966] error 0.041875> [hit 11]Database connection failed - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Plugin/Database.pm l. 116
[5966]  core 0.042070> [hit 11]request to /login crashed: Can't bless non-reference value at /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Plugin/Database.pm line 130. in /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Handler.pm l. 76
[5966]  core 0.042358> [hit 11]new Error object: [500] Can't bless non-reference value at /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Plugin/Database.pm line 130. in /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Error.pm l. 30
[5966]  core 0.042973> [hit 11]response: 500 in /opt/local/lib/perl5/site_perl/5.10.1/Dancer/Handler.pm l. 131

It would be more useful to have database be undef instead so I can check for this in a before sub.

bigpresh commented 13 years ago

Ah, good catch, that was indeed stupid.

Version 1.21 released to CPAN which returns undef if the connection failed, rather than attempting to re-bless the undefined value and blowing up.

Thanks!