Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the JSON-RPC-Dispatcher CPAN distribution.

Report information
The Basics
Id: 59083
Status: resolved
Priority: 0/
Queue: JSON-RPC-Dispatcher

People
Owner: Nobody in particular
Requestors: RHOELZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.0502
Fixed in: (no value)



Subject: Parse error persists between RPC calls
Currently, submitting a request that has a JSON parse error will cause that parse error to show up for subsequent requests. A test file and a patch have been attached. Example: request('{id:1') -> { jsonrpc: '2.0', error: { message: 'Parse error.', ... }} request("{jsonrpc: '2.0', id: 1, method: 'echo', params: ['hello']}) -> { jsonrpc: '2.0', error: { message: 'Parse error.', ...}}
Subject: jrd-fix.patch
--- a/Dispatcher.pm 2010-07-03 17:36:34.000000000 -0500 +++ b/Dispatcher.pm 2010-07-03 17:52:53.000000000 -0500 @@ -145,18 +145,21 @@ is => 'rw', default => undef, predicate => 'has_error_code', + clearer => 'clear_error_code', ); #-------------------------------------------------------- has error_message => ( is => 'rw', default => undef, + clearer => 'clear_error_message', ); #-------------------------------------------------------- has error_data => ( is => 'rw', default => undef, + clearer => 'clear_error_data', ); #-------------------------------------------------------- @@ -166,6 +169,15 @@ ); #-------------------------------------------------------- +sub clear_error { + my ($self) = @_; + + $self->clear_error_code; + $self->clear_error_message; + $self->clear_error_data; +} + +#-------------------------------------------------------- sub register { my ($self, $name, $sub, $options) = @_; my $rpcs = $self->rpcs; @@ -355,6 +367,7 @@ my $request = Plack::Request->new($env); $log->info("REQUEST: ".$request->content) if $log->is_info; + $self->clear_error; my $procs = $self->acquire_procedures($request); my $rpc_response;
Subject: 01-parse-error.t
use strict; use warnings; use lib '../lib'; use JSON qw(from_json to_json); use JSON::RPC::Dispatcher; use Test::More tests => 6; use Test::WWW::Mechanize::PSGI; my $rpc = JSON::RPC::Dispatcher->new; my $endpoint = 'http://localhost'; my $mech = Test::WWW::Mechanize::PSGI->new( app => $rpc->to_app, ); $rpc->register(echo => sub { return $_[0]; }); sub do_jsonrpc { my ( $content ) = @_; my $req = HTTP::Request->new(POST => $endpoint); $req->header('Content-type' => 'application/json'); $req->header('Content-length' => length($content)); $req->content($content); $mech->request($req); } do_jsonrpc(to_json({ jsonrpc => '2.0', id => 0, method => 'echo', params => ['hello'], })); ok($mech->res->is_success); is_deeply(from_json($mech->content), { jsonrpc => '2.0', id => 0, result => 'hello', }); do_jsonrpc('{id:1'); is(500, $mech->res->code); is_deeply(from_json($mech->content), { jsonrpc => '2.0', error => { code => -32700, message => 'Parse error.', data => '{id:1', }, }); do_jsonrpc(to_json({ jsonrpc => '2.0', id => 1, method => 'echo', params => ['hello'], })); ok($mech->res->is_success); is_deeply(from_json($mech->content), { jsonrpc => '2.0', id => 1, result => 'hello', });
Patch applied and 0.0503 has been released to PAUSE. Sorry for the delay, I wasn't around this weekend. By the way, super nice find. I've been using the module in production for 6 months and didn't find this problem.