shardlab / discordrb

Discord API for Ruby
MIT License
532 stars 98 forks source link

NoMethodError when removed_member_ids is nil #186

Open holdank opened 2 years ago

holdank commented 2 years ago

Summary

seeing this error result in closed connections

[ERROR` : websocket @ 2022-10-16 15:22:46.660] Exception: #<NoMethodError: undefined method `each' for nil:NilClass

        data['removed_member_ids'].each do |member_id|
                                  ^^^^^>
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/bot.rb:1603:in `handle_dispatch'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/bot.rb:769:in `dispatch'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:730:in `handle_dispatch'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:694:in `handle_message'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:631:in `websocket_loop'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:579:in `connect'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:473:in `block in connect_loop'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:472:in `loop'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:472:in `connect_loop'
[ERROR : websocket @ 2022-10-16 15:22:46.661] /usr/local/rvm/gems/ruby-3.1.2/bundler/gems/discordrb-1cd5603d23e0/lib/discordrb/gateway.rb:168:in `block in run_async'
[ERROR : websocket @ 2022-10-16 15:25:34.644] The websocket connection has closed: (no information)
[INFO : websocket @ 2022-10-16 15:25:34.644] Instant reconnection flag was set - reconnecting right away
[INFO : websocket @ 2022-10-16 15:25:34.984] Resumed

looks like added_members and removed_member_ids falls back to empty array here in thread.rb, but this code in bot.rb is still accessing the data hash directly which can result in these being nil and causing the error.

The closed connection happens a few minutes later - I was assuming it was related, but it may not be.


Environment

ubuntu 20.0.4

Ruby version:

3.1.2

Discordrb version:

specs: discordrb (3.4.2) discordrb-webhooks (~> 3.4.2) ffi (>= 1.9.24) opus-ruby rest-client (>= 2.0.0) websocket-client-simple (>= 0.3.0) discordrb-webhooks (3.4.2) rest-client (>= 2.0.0)

Daniel-Worrall commented 2 years ago

Introduced in #141, these fields are optional.

Will send a PR

holdank commented 2 years ago

Ah i see i had the flow backwards - thanks for taking a look.