discordrb
discordrb copied to clipboard
'Inline' `Bot#gateway_check` assertion
Summary
Bot#gateway_check is a common method used to assert that a gateway connection is active, called as the first step in many bot methods. By using the three argument form of raise, along with caller, we can hide the gateway_check call from the traceback, making the source of the error clearer.
With this change, after calling bot.servers:
/home/biqqles/Code/discordrb/lib/discordrb/bot.rb:180:in `servers': A gateway connection is necessary to call this method! You'll have to do it inside any event (e.g. `ready`) or after `bot.run :async`. (RuntimeError)
from /home/biqqles/Code/discordrb/lib/test.rb:5:in `<main>
Before:
/home/biqqles/Code/discordrb/lib/discordrb/bot.rb:902:in `gateway_check': A gateway connection is necessary to call this method! You'll have to do it inside any event (e.g. `ready`) or after `bot.run :async`. (RuntimeError)
from /home/biqqles/Code/discordrb/lib/discordrb/bot.rb:180:in `servers'
from /home/biqqles/Code/discordrb/lib/test.rb:5:in `<main>'
Changed
Bot#gateway_checkis now hidden from the traceback it causes
@Daniel-Worrall I'd like your input here. I think it's a fine change to make but one could argue for more explicit backtraces