From aab533623e3b40d837d05238bcefb8c2a0e5137b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 29 Feb 2008 04:17:23 +0000 Subject: [PATCH] Add a field to the InvalidParam exception. Use it in Ship.pm for documenting bad requested classes, and test its use. --- lib/WebGUI/Exception.pm | 5 +++++ lib/WebGUI/Shop/Ship.pm | 2 +- t/Shop/Ship.t | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Exception.pm b/lib/WebGUI/Exception.pm index 313c272fc..61392aa3b 100644 --- a/lib/WebGUI/Exception.pm +++ b/lib/WebGUI/Exception.pm @@ -28,6 +28,7 @@ use Exception::Class ( 'WebGUI::Error::InvalidParam' => { isa => 'WebGUI::Error', description => "Expected to get a param we didn't get.", + fields => ["param"], }, 'WebGUI::Error::ObjectNotFound' => { isa => 'WebGUI::Error', @@ -120,6 +121,10 @@ The object type we got. Used when an invalid parameter is passed into a subroutine. +=head3 param + +Used to return the bad parameter, if present. + =head2 WebGUI::Error::ObjectNotFound Used when an object is trying to be retrieved, but does not exist. ISA WebGUI::Error. diff --git a/lib/WebGUI/Shop/Ship.pm b/lib/WebGUI/Shop/Ship.pm index 8d058c1de..7906bf52e 100644 --- a/lib/WebGUI/Shop/Ship.pm +++ b/lib/WebGUI/Shop/Ship.pm @@ -56,7 +56,7 @@ sub create { my $requestedClass = shift; WebGUI::Error::InvalidParam->throw(error => q{Must provide a class to create an object}) unless defined $requestedClass; - WebGUI::Error::InvalidParam->throw(error => qq{The requested class $requestedClass is not enabled in your WebGUI configuration file}) + WebGUI::Error::InvalidParam->throw(error => q{The requested class is not enabled in your WebGUI configuration file}, param => $requestedClass) unless isIn($requestedClass, @{ WebGUI::Shop::Ship->getDrivers($session) } ); my $options = shift; WebGUI::Error::InvalidParam->throw(error => q{You must pass a hashref of options to create a new ShipDriver object}) diff --git a/t/Shop/Ship.t b/t/Shop/Ship.t index 6ea90c626..229e4f09e 100644 --- a/t/Shop/Ship.t +++ b/t/Shop/Ship.t @@ -109,7 +109,8 @@ isa_ok($e, 'WebGUI::Error::InvalidParam', 'create croaks without a configured cl cmp_deeply( $e, methods( - error => 'The requested class WebGUI::Shop::ShipDriver::FreeShipping is not enabled in your WebGUI configuration file', + error => 'The requested class is not enabled in your WebGUI configuration file', + param => 'WebGUI::Shop::ShipDriver::FreeShipping', ), 'create croaks without a configured class', );