sinatra-swagger-exposer icon indicating copy to clipboard operation
sinatra-swagger-exposer copied to clipboard

NameError: uninitialized constant Sinatra::JSON::ParserError

Open dnlcv opened this issue 9 years ago • 1 comments

Hello @archiloque ! I'm trying to test the sinatra-swagger-exposer in one of my sinatra apps. However I'm getting the following error:

NameError: uninitialized constant Sinatra::JSON::ParserError
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-swagger-exposer-0.4.0/lib/sinatra/swagger-exposer/processing/swagger-response-processor.rb:36:in `rescue in validate_response'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-swagger-exposer-0.4.0/lib/sinatra/swagger-exposer/processing/swagger-response-processor.rb:34:in `validate_response'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-swagger-exposer-0.4.0/lib/sinatra/swagger-exposer/processing/swagger-request-processor.rb:98:in `validate_response'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-swagger-exposer-0.4.0/lib/sinatra/swagger-exposer/swagger-exposer.rb:195:in `block in route'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1610:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1610:in `block in compile!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `[]'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:994:in `route_eval'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1015:in `block in process_route'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `catch'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `process_route'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:973:in `block in route!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `each'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `route!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1085:in `block in dispatch!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1082:in `dispatch!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `block in call!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `call!'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:895:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/show_exceptions.rb:25:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/show_exceptions.rb:25:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/puma-3.4.0/lib/puma/configuration.rb:224:in `call'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/puma-3.4.0/lib/puma/server.rb:569:in `handle_request'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/puma-3.4.0/lib/puma/server.rb:406:in `process_client'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/puma-3.4.0/lib/puma/server.rb:271:in `block in run'
        /Users/daniel.campos/.rvm/gems/ruby-2.0.0-p353/gems/puma-3.4.0/lib/puma/thread_pool.rb:114:in `call'

I added your gem to my project's Gemfile and installed it using bundler:

$ bundle install
Using rake 11.1.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.6
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using nokogiri 1.6.7.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using loofah 2.0.3
Using rails-html-sanitizer 1.0.3
Using actionview 4.2.6
Using backports 3.6.8
Using cause 0.1
Using daemons 1.2.3
Using diff-lcs 1.2.5
Using multipart-post 2.0.0
Using faraday 0.9.2
Using faraday_middleware 0.9.2
Using git-version-bump 0.15.1
Using gli 2.13.4
Using hash-deep-merge 0.1.1
Using hashie 3.4.3
Using influxdb 0.3.5
Using lazy_high_charts 1.5.5
Using mime-types 2.6.2
Using moneta 0.8.0
Using multi_json 1.11.2
Using puma 3.4.0
Using rack 1.6.4
Using rack-contrib 1.4.0
Using rack-protection 1.5.3
Using rack-test 0.6.3
Using rspec-support 3.4.1
Using rspec-core 3.4.4
Using rspec-expectations 3.4.0
Using rspec-mocks 3.4.1
Using rspec 3.4.0
Using sequel 4.34.0
Using tilt 1.4.1
Using sinatra 1.4.7
Using sinatra-contrib 1.4.7
Using sinatra-flash 0.3.0
Using sinatra-swagger-exposer 0.4.0
Using websocket-extensions 0.1.2
Using websocket-driver 0.6.3
Using slack-ruby-client 0.7.0
Using sqlite3 1.3.11
Using zabbixapi 2.4.7
Using bundler 1.7.4
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

From what I can tell the issue is happening when executing this line in lib/sinatra/swagger-exposer/processing/swagger-response-processor.rb

rescue JSON::ParserError => e

After some debugging I changed the rescue to rescue => e and executed another test. This time the error happened in the line

parsed_response_body = JSON.parse(response_body)

and the error was

Error during processing: undefined method `parse' for Sinatra::JSON:Module

It seems that for some reason the JSON module is not being loaded correctly.

Have you seen this error before? Could this be related to my environment, gems or ruby version?

dnlcv avatar Aug 09 '16 02:08 dnlcv

Hello @danmarte , I had completely the same problem and realized that the problem was caused by Sinatra::JSON module. Maybe there is another solution but I just switched from that module to normal json library.

jarkaK avatar Oct 19 '16 07:10 jarkaK