Incapamentum / Exalted-Sage

Discord bot that does API requests to retrieve a collection of daily achievements for the next day and pushes an alert when any that is in a watchlist shows up.
3 stars 0 forks source link

Unhandled Exception in MessageReceived Handler (System.NullReferenceException) #14

Open Incapamentum opened 1 year ago

Incapamentum commented 1 year ago

A System.NullReferenceException is being thrown within the MessageRecived handler (i.e. the MessageEventHandler class). This line of code seems to be where the error is occuring.

Happens infrequently, but currently I suspect the cause of it may be that it's attempting to grab the ID of a non-existent category(?) or something without a channel. May be difficult to reproduce.

Image of stack trace is included: MessageEventHandler_l69

Incapamentum commented 1 year ago

Unsure if this stack trace dump is related to this error, but to keep the possibility open, I'll be including it in this issue. If it turns out to be a separate and unique error from this one, a new issue will be opened.

23:15:15 Gateway     A MessageReceived handler has thrown an unhandled exception.:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Bot.Handlers.MessageEventHandler.MessageReceivedAsync(SocketMessage message) in C:\Workspaces\Visual-Studio\Exalted-Sage\New\bot\Handlers\MessageEventHandler.cs:line 91
   at Discord.EventExtensions.InvokeAsync[T](AsyncEvent`1 eventHandler, T arg)
   at Discord.WebSocket.DiscordSocketClient.TimeoutWrap(String name, Func`1 action)
Incapamentum commented 1 year ago

This error still appears, even with moving to a new VPS service. Still unsure how to reproduce the error in dev, but will have to consider different things.

18:59:09 Gateway     A MessageReceived handler has thrown an unhandled exception.:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Bot.Handlers.MessageEventHandler.MessageReceivedAsync(SocketMessage message) in /home/runner/work/Exalted-Sage/Exalted-Sage/New/bot/Handlers/MessageEventHandler.cs:line 91
   at Discord.EventExtensions.InvokeAsync[T](AsyncEvent`1 eventHandler, T arg)
   at Discord.WebSocket.DiscordSocketClient.TimeoutWrap(String name, Func`1 action)
Incapamentum commented 1 year ago

Note: the code for this particular bug has changed, although I suspect that the issue persists.

The other day I actually took note that the error only comes up whenever a message is sent through a thread. If that's the case, a fix for this would be to simply exclude all messages originating from threads.