Blockheads-Messagebot / MessageBot

Automatically respond to events in chat on your server!
GNU General Public License v3.0
6 stars 3 forks source link

Errors thrown by event listeners should not affect the chat watcher's behavior #58

Closed Bibliofile closed 5 years ago

Bibliofile commented 5 years ago

The code here: https://github.com/Blockheads-Messagebot/MessageBot/blob/master/src/chatWatcher.ts#L163-L174

Contains a rather subtle bug. When this.parse is called, it will fire events. If any event handler throws an error, it will bubble up until it is caught either on line 110, line 122, or line 169.

If the error makes it all the way to 169 (it was thrown by a message or other listener) then the code assumes that a network error has occurred and, after waiting 30 seconds, tries to fetch messages from message 0 - when the server was started.

30 seconds later, messages will be fetched from the start, reparsed (likely causing spam), and the error will probably be thrown again, resulting in the same behavior.

AC:

To reproduce:

Add a command:

MessageBot.registerExtension('fail', (ex, world) => {
  world.addCommand('fail', () => { throw new Error() })
})

Type /fail in the chat. No error will be logged and the bot will enter an infinite loop.

Bibliofile commented 5 years ago

Resolved by #61