From: Peter Rabbitson Date: Tue, 26 Oct 2010 17:42:29 +0000 (+0200) Subject: Fail gracefully on Config::Any PROFILE-loading errors X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a2a7b236736a0ed34fb60ccd1265f933393aa43;p=dbsrgits%2FDBIx-Class-Historic.git Fail gracefully on Config::Any PROFILE-loading errors --- diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index 893a6b1..d18431e 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -11,6 +11,10 @@ use Carp; # POD is generated automatically by calling _gen_pod from the # Makefile.PL in $AUTHOR mode +my $json_any = { + 'JSON::Any' => '1.22', +}; + my $moose_basic = { 'Moose' => '0.98', 'MooseX::Types' => '0.21', @@ -23,9 +27,9 @@ my $replicated = { my $admin_basic = { %$moose_basic, + %$json_any, 'MooseX::Types::Path::Class' => '0.05', 'MooseX::Types::JSON' => '0.02', - 'JSON::Any' => '1.22', 'namespace::autoclean' => '0.09', }; @@ -88,7 +92,6 @@ my $reqs = { }, }, - test_pod => { req => { 'Test::Pod' => '1.41', @@ -114,6 +117,10 @@ my $reqs = { }, }, + test_prettydebug => { + req => $json_any, + }, + test_leaks => { req => { 'Test::Memory::Cycle' => '0', diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 34c3eac..e26295b 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -68,7 +68,14 @@ sub new { require DBIx::Class::Storage::Debug::PrettyPrint; if ($profile =~ /^\.?\//) { require Config::Any; - my $cfg = Config::Any->load_files({ files => [$profile], use_ext => 1 }); + + my $cfg = try { + Config::Any->load_files({ files => [$profile], use_ext => 1 }); + } catch { + # sanitize the error message a bit + $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; + $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_"); + }; my ($filename, $config) = %{$cfg->[0]}; $debugobj = DBIx::Class::Storage::Debug::PrettyPrint->new($config) @@ -135,7 +142,7 @@ Throws an exception - croaks. sub throw_exception { my $self = shift; - if ($self->schema) { + if (ref $self and $self->schema) { $self->schema->throw_exception(@_); } else { diff --git a/t/storage/dbic_pretty.t b/t/storage/dbic_pretty.t index ab19c8a..6a698ef 100644 --- a/t/storage/dbic_pretty.t +++ b/t/storage/dbic_pretty.t @@ -4,6 +4,12 @@ use lib qw(t/lib); use DBICTest; use Test::More; +BEGIN { + require DBIx::Class; + plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_prettydebug') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_prettydebug'); +} + BEGIN { delete @ENV{qw(DBIC_TRACE_PROFILE)} } {