From: Alexander Hartmaier Date: Fri, 20 Aug 2010 15:00:26 +0000 (+0200) Subject: remove trailing newlines from error messages X-Git-Tag: 2.002003~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=7821bdec3826d11fe878d13859c15d7f2c5b0cfa remove trailing newlines from error messages --- diff --git a/Changes b/Changes index 26d09ed..917a214 100644 --- 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 diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 52202a0..bfd5024 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -916,7 +916,14 @@ push_error stores an error message into the stash to be later retrieved by Lstash->{_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 diff --git a/t/rest/list.t b/t/rest/list.t index ab2aa4e..783aa4c 100644 --- a/t/rest/list.t +++ b/t/rest/list.t @@ -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' ); } {