iande / onstomp

A STOMP messaging client library for Ruby
http://mathish.com/projects/onstomp.html
Other
23 stars 11 forks source link

ERROR: undefined method `empty?' for true:TrueClass when pass true as the value of client header attribute #32

Closed sonncui closed 6 years ago

sonncui commented 6 years ago

We create a client:

client = OnStomp.connect("stomp://mq:#{mq_port}")

Set

headers = {:persistent=>true}
data = {event: "save", id: "balabala"}

Call

client.send(
          "/queue/##{our_project_queue}",
          data.to_json,
          headers
        )

Then we get an error below:

NoMethodError: undefined method `empty?' for true:TrueClass
    from (irb):44:in `block (2 levels) in irb_binding'
    from (irb):44:in `delete_if'
    from (irb):44:in `block in irb_binding'
    from (irb):43:in `each'
    from (irb):43:in `inject'
    from (irb):43
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/app_rails_loader.rb:45:in `require'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/app_rails_loader.rb:45:in `block in exec_app_rails'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/app_rails_loader.rb:34:in `loop'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/app_rails_loader.rb:34:in `exec_app_rails'
    from /usr/local/bundle/gems/railties-4.2.10/lib/rails/cli.rb:5:in `<top (required)>'
    from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/bundle/gems/railties-4.2.10/bin/rails:9:in `<top (required)>'
    from /usr/local/bundle/bin/rails:22:in `load'
    from /usr/local/bundle/bin/rails:22:in `<main>'

And after our analyze, the code in the repo: https://github.com/iande/onstomp/blob/master/lib/onstomp/connections/stomp_1.rb#L57 which not handle the value without a method #empty? (eg: we give the header {:persistent=>true})

So how do we handle this kind of case?

iande commented 6 years ago

I think, in general, header values are meant to be supplied as strings (they will certainly be serialized as such) so one option would be:

headers = { :persistent => 'true' }

Another possibility is to explicitly convert header values to strings by use of #to_s. I'm actually disappointed with myself for not having done this already 😞

Finally, your PR may solve the issue as well, I'll take a look at it now!

iande commented 6 years ago

Thank you for your contributions regarding this issue as well as brining the CI config and development dependencies up to date. I have merged everything in the master branch as well as published a new patch version of onstomp (1.0.10) with the changes.