[libbread-board-perl] 08/66: make some error messages a bit more helpful.

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 21:23:31 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libbread-board-perl.

commit 0d1d62626321e281d9481d011de5204bb347e364
Author: Jason Galea <jason at lecstor.com>
Date:   Thu Dec 15 15:34:43 2011 +1000

    make some error messages a bit more helpful.
---
 lib/Bread/Board.pm      |   16 +++++++++++-----
 t/027_sugar_w_include.t |    2 +-
 t/301_lecstor.t         |   24 +++++++++++-------------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/lib/Bread/Board.pm b/lib/Bread/Board.pm
index 1c86562..4162f4c 100644
--- a/lib/Bread/Board.pm
+++ b/lib/Bread/Board.pm
@@ -43,7 +43,13 @@ sub set_root_container {
 
 sub container ($;$$) {
     my $name        = shift;
-    my $name_is_obj = blessed $name && $name->isa('Bread::Board::Container') ? 1 : 0;
+
+    my $name_is_obj = 0;
+    if (blessed $name){
+        confess 'an object used as a container must inherit from Bread::Board::Container'
+            unless $name->isa('Bread::Board::Container');
+        $name_is_obj = 1;
+    }
 
     my $c;
     if ( scalar @_ == 0 ) {
@@ -120,7 +126,7 @@ sub include ($) {
     else {
         confess "Couldn't compile $file: $@" if $@;
         confess "Couldn't open $file for reading: $!" if $!;
-        confess "Unknown error when compiling $file";
+        confess "$file compiles to false.";
     }
 }
 
@@ -144,7 +150,7 @@ sub service ($@) {
         }
     }
     else {
-        confess "I don't understand @_";
+        confess "A service is defined by a name and either a single value or hash of\nparameters, you have supplied neither with:\n\t at _";
     }
     return $s unless defined $CC;
     $CC->add_service($s);
@@ -168,7 +174,7 @@ sub typemap ($@) {
     my $type = shift;
 
     (scalar @_ == 1)
-        || confess "Too many (or too few) arguments to typemap";
+        || confess "typemap has one argument at a time";
 
     my $service;
     if (blessed $_[0]) {
@@ -179,7 +185,7 @@ sub typemap ($@) {
             $service = $_[0]->infer_service( $type );
         }
         else {
-            confess "No idea what to do with a " . $_[0];
+            confess $_[0] . " doesn't do Bread::Board::Service and isn't a Bread::Board::Service::Inferred. No idea what to do with it.";
         }
     }
     else {
diff --git a/t/027_sugar_w_include.t b/t/027_sugar_w_include.t
index b35c3f8..1ad3e29 100644
--- a/t/027_sugar_w_include.t
+++ b/t/027_sugar_w_include.t
@@ -19,7 +19,7 @@ like(exception { include "$FindBin::Bin/lib/doesnt_exist.bb" },
      "we get appropriate errors for files that don't exist");
 
 like(exception { include "$FindBin::Bin/lib/false.bb" },
-     qr/Unknown error when compiling .*/,
+     qr/compiles to false/,
      "we get appropriate errors for files that evaluate to false");
 
 {
diff --git a/t/301_lecstor.t b/t/301_lecstor.t
index bf0b93b..62ad651 100644
--- a/t/301_lecstor.t
+++ b/t/301_lecstor.t
@@ -7,32 +7,32 @@ use Test::More;
 use Test::Fatal;
 
 use Bread::Board;
-use Bread::Board::Container;
 
 
 my $exception = exception { container (bless {}, 'NameObject') };
-like( $exception, qr/^Attribute \(name\)/, "exception begins with: Attribute (name)" );
+like( $exception, qr/^an object used as a container/, "exception begins with: an object used as a container" );
 
 
 ok ( (container 'MyApp' => as { service 'service_name',
                                   'service_type' => 'Block',
-                                  'block' => sub{} } ), 'hmmm' );
+                                  'block' => sub{} } ), 'set service with service type name' );
 
-my $c = Bread::Board::Container->new(name => '/');
+
+my $c = container 'Application';
 isa_ok($c, 'Bread::Board::Container');
 
 
-ok ( (container $c), 'name is object' );
+ok ( (container $c), 'set container with object' );
 
 
-$exception = exception{ container $c, 'summat', 'summat else' };
+$exception = exception{ container $c, 'thing1', 'thing2' };
 like( $exception, qr/^container\(\$object, \.\.\.\) is not supported/, 'exception begins with: container($object, ...) is not supported' );
 
 
 $exception = exception{ 
-    container 'MyApp' => as { service 'service_name', 'summat', 'summat else', 'summat else again' }
+    container 'MyApp' => as { service 'service_name', 'thing1', 'thing2', 'trouble' }
 };
-like( $exception, qr/^I don't understand/, 'exception begins with: I don\'t understand' );
+like( $exception, qr/^A service is defined by/, 'exception begins with: A service is defined by' );
 
 {
     package MyNonService;
@@ -48,16 +48,14 @@ $exception = exception{
 like( $exception, qr/^The service class must do the Bread::Board::Service role/, 'exception begins with: The service class must do the Bread::Board::Service role' );
 
 
-$exception = exception{ 
-    typemap ('Type')
-};
-like( $exception, qr/^Too many \(or too few\)/, 'exception begins with: Too many (or too few)' );
+$exception = exception{ typemap ('Type') };
+like( $exception, qr/^typemap has one argu/, 'exception begins with: typemap has one argu' );
 
 
 $exception = exception{ 
     typemap ('Type', MyNonService->new)
 };
-like( $exception, qr/^No idea what to do with a/, 'exception begins with: No idea what to do with a' );
+like( $exception, qr/doesn't do Bread::Board::Service/, 'exception contains: doesn\'t do Bread::Board::Service' );
 
 
 done_testing;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libbread-board-perl.git



More information about the Pkg-perl-cvs-commits mailing list