remove trailing newlines from error messages
Alexander Hartmaier [Fri, 20 Aug 2010 15:00:26 +0000 (17:00 +0200)]
Changes
lib/Catalyst/Controller/DBIC/API.pm
t/rest/list.t

diff --git a/Changes b/Changes
index 26d09ed..917a214 100644 (file)
--- a/Changes
+++ b/Changes
@@ -9,6 +9,7 @@ Revision history for Catalyst-Controller-DBIC-API: {{ $dist->version }}
 - Fixed static configured page attribute not being used (RT#56226)
 - Test use_json_boolean true
 - Fixed search attribute generation for nonexistent relationships
+- Remove trailing newlines from error messages
 
 2.002002  2010-08-03 14:40:50 Europe/Vienna
 
index 52202a0..bfd5024 100644 (file)
@@ -916,7 +916,14 @@ push_error stores an error message into the stash to be later retrieved by L</en
 sub push_error
 {
     my ( $self, $c, $params ) = @_;
-    push( @{$c->stash->{_dbic_crud_errors}}, $params->{message} || 'unknown error' );
+    my $error = 'unknown error';
+    if (exists $params->{message}) {
+        $error = $params->{message};
+        # remove newline from die "error message\n" which is required to not
+        # have the filename and line number in the error text
+        $error =~ s/\n$//;
+    }
+    push( @{$c->stash->{_dbic_crud_errors}}, $error);
 }
 
 =method_protected get_errors
index ab2aa4e..783aa4c 100644 (file)
@@ -143,7 +143,7 @@ my $track_list_url = "$base/api/rest/track";
     $mech->request($req);
     cmp_ok( $mech->status, '==', 400, 'attempt with nonexisting relationship fails' );
     my $response = JSON::Any->Load( $mech->content);
-    is_deeply( $response->{messages}, ["track is neither a relationship nor a column\n"], 'correct error message returned' );
+    is_deeply( $response->{messages}, ['track is neither a relationship nor a column'], 'correct error message returned' );
 }
 
 {