bitboxer / jimson

JSON-RPC 2.0 client and server for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return only jimson exceptions

simi opened this issue · comments

Jimson should send back only errors from Jimson::Server::Error or inherited ones. Now it can send errors like NoMethodError.

If you like it, I'll contribute this feature.

The intention is definitely as you say; Jimson should only raise errors from Jimson::Server::Error. Did I miss some place(s) where other errors can be thrown?

I got this, during running tests:

{"jsonrpc"=>"2.0", "error"=>{"code"=>-32099, "message"=>"Application error: undefined method `from_json' for Api::Actions::User:Class /home/retro/work/my/project/app/api/actions/user.rb:37:in `update'\n/home/retro/work/my/project/app/api/users.rb:22:in `block in <module:Users>'\n/home/retro/work/eman/jimson-eom/lib/jimson/eom/methods.rb:7:in `block in method'\n/home/retro/work/eman/jimson/lib/jimson/server.rb:177:in `dispatch_request'\n/home/retro/work/eman/jimson/lib/jimson/server.rb:136:in `create_response'\n/home/retro/work/eman/jimson/lib/jimson/server.rb:100:in `handle_request'\n/home/retro/work/eman/jimson/lib/jimson/server.rb:77:in `process'\n/home/retro/work/eman/jimson/lib/jimson/server.rb:66:in `call'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/rack-test-0.6.1/lib/rack/mock_session.rb:30:in `request'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/rack-test-0.6.1/lib/rack/test.rb:219:in `process_request'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/rack-test-0.6.1/lib/rack/test.rb:66:in `post'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/forwardable.rb:201:in `post'\n/home/retro/work/my/project/test/support/api_case.rb:27:in `post_json'\n/home/retro/work/my/project/test/support/api_case.rb:19:in `post_api'\n/home/retro/work/my/project/test/api/users_test.rb:55:in `test_update_user'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:949:in `run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:787:in `block in _run_suite'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:780:in `map'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:780:in `_run_suite'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:565:in `block in _run_suites'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:563:in `each'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:563:in `_run_suites'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:746:in `_run_anything'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/guard-minitest-0.5.0/lib/guard/minitest/runners/version_2_runner.rb:12:in `_run_anything'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:909:in `run_tests'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:896:in `block in _run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:895:in `each'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:895:in `_run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:21:in `run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:630:in `run'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-testunit-0.0.8/lib/spork/test_framework/test_unit.rb:80:in `run_tests'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:13:in `block in run'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/forker.rb:21:in `block in initialize'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/forker.rb:18:in `fork'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/forker.rb:18:in `initialize'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `new'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `run'\n/home/retro/.rvm/gems/ruby-1.9.3-p125@eom/gems/spork-0.9.0/lib/spork/server.rb:48:in `run'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'\n/home/retro/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'"}, "id"=>1}

I think, there should be returned some global error without stack trace. Maybe I just don't understand @chriskite.

That actually is a Jimson::Server::Error::ApplicationError being returned by the server, basically saying that in your code there was a NoMethodError raised. The stacktrace is provided so that you can debug the issue.

Perhaps it is not desirable to have the server expose so much error information in this case. I could have the server by default only say "Application error", and create a debug mode that would give this more detailed information.

Thoughts?

Yes, that's exactly what I mean. I'm working on it.

Hi chriskite/simi , how can we define custome error codes and send those as response?.

For ex: login request we have sent to server if login successful result will be "0k" of not we should have response object with error = {code : 2000,message:"unable to login"}.

How can we achieve this with jimson implementation, can you guys please explain me on this pls.