Erisa / Cliptok

Moderation Discord bot for Microsoft Community.
https://msft.chat/about/bots.html#cliptok
MIT License
63 stars 26 forks source link

Todo: Make UnpackLogConfigAsync more resilient #215

Closed Erisa closed 3 months ago

Erisa commented 4 months ago

See #214

If something goes wrong in UnpackLogConfigAsync it doesn't seem to log the error and the bot continues execution in a degraded state.

Erisa commented 3 months ago

I don't think the exception was swallowed, it's more like it isn't shown in the Cliptok log thread because well.. it can't be, since log channel helper isn't ready yet.

[2024-08-11 00:26:30 +01:00] [Error] Event handler exception for event "DSharpPlus.EventArgs.SessionCreatedEventArgs" thrown from "System.Threading.Tasks.Task OnReady(DSharpPlus.DiscordClient, DSharpPlus.EventArgs.SessionCreatedEventArgs)" (defined in "Cliptok.Events.ReadyEvent").
System.Exception: Exception of type 'System.Exception' was thrown.
   at Cliptok.Helpers.LogChannelHelper.UnpackLogConfigAsync(ConfigJson config) in C:\Users\Erisa\Work\Cliptok\Helpers\LogChannelHelper.cs:line 18
   at Cliptok.Events.ReadyEvent.OnReady(DiscordClient client, SessionCreatedEventArgs _) in C:\Users\Erisa\Work\Cliptok\Events\ReadyEvent.cs:line 13
   at DSharpPlus.AsyncEvents.AsyncEvent`2.<>c__DisplayClass8_0.<<InvokeAsync>b__0>d.MoveNext()

since this is part of OnReady, we can try/catch and either throw an error in another channel or panic and quit the bot.

Erisa commented 3 months ago

we can try/catch and either throw an error in another channel or panic and quit the bot.

The latter was chosen. Between this and https://github.com/Erisa/Cliptok/commit/f8933a906d188e4b0e2b147c74494c3036ac7abc, the problem should be largely resolved.