From b9b057e1f1b98e0c35b423ec7dc9066884f994bb Mon Sep 17 00:00:00 2001 From: Noi Date: Mon, 4 Sep 2023 16:15:48 -0700 Subject: [PATCH] Remove extraneous log messages In particular, these changes filter out the reporting of any errors occurring during the bot shutdown process. --- BackgroundServices/AutoUserDownload.cs | 6 +++++- ShardInstance.cs | 1 + ShardManager.cs | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BackgroundServices/AutoUserDownload.cs b/BackgroundServices/AutoUserDownload.cs index c43f8f6..a9f8e15 100644 --- a/BackgroundServices/AutoUserDownload.cs +++ b/BackgroundServices/AutoUserDownload.cs @@ -57,7 +57,11 @@ class AutoUserDownload : BackgroundService { await Task.Delay(200, CancellationToken.None); // Delay a bit (reduces the possibility of hanging, somehow). var dl = guild.DownloadUsersAsync(); - dl.Wait((int)RequestTimeout.TotalMilliseconds / 2, token); + try { + dl.Wait((int)RequestTimeout.TotalMilliseconds / 2, token); + } catch (Exception) { } + if (token.IsCancellationRequested) return; // Skip all reporting, error logging on cancellation + if (dl.IsFaulted) { Log("Exception thrown by download task: " + dl.Exception); break; diff --git a/ShardInstance.cs b/ShardInstance.cs index 62ac25b..c05000d 100644 --- a/ShardInstance.cs +++ b/ShardInstance.cs @@ -94,6 +94,7 @@ public sealed class ShardInstance : IDisposable { return Task.CompletedTask; } + if (arg.Exception is TaskCanceledException) return Task.CompletedTask; // We don't ever need to know these... Log("Discord.Net exception", $"{arg.Exception.GetType().FullName}: {arg.Exception.Message}"); } diff --git a/ShardManager.cs b/ShardManager.cs index 5fe1abd..bc9223e 100644 --- a/ShardManager.cs +++ b/ShardManager.cs @@ -61,8 +61,6 @@ class ShardManager : IDisposable { if (!Task.WhenAll(shardDisposes).Wait(30000)) { Log("Warning: Not all shards terminated cleanly after 30 seconds. Continuing..."); } - - Log($"Uptime: {Program.BotUptime}"); } private void Log(string message) => Program.Log(nameof(ShardManager), message);