chore: clean up .net sentry exceptions
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled

This commit is contained in:
alyssa 2026-01-25 06:53:15 -05:00
parent ce0983ba16
commit 09ed215e6c
6 changed files with 38 additions and 17 deletions

View file

@ -2,6 +2,8 @@ using Autofac.Extensions.DependencyInjection;
using PluralKit.Core;
using Sentry;
using Serilog;
namespace PluralKit.API;
@ -21,9 +23,16 @@ public class Program
opts.Dsn = config.SentryUrl ?? "";
opts.Release = BuildInfoService.FullVersion;
opts.AutoSessionTracking = true;
// opts.DisableTaskUnobservedTaskExceptionCapture();
opts.DisableUnobservedTaskExceptionCapture();
});
TaskScheduler.UnobservedTaskException += (_, e) =>
{
foreach (var inner in e.Exception.Flatten().InnerExceptions)
SentrySdk.CaptureException(inner);
e.SetObserved();
};
await host.Services.GetRequiredService<RedisService>().InitAsync(config);
await host.RunAsync();
}

View file

@ -442,7 +442,7 @@ public class ProxiedMessage
return;
}
await ctx.Reply(components: await _embeds.CreateAuthorMessageComponents(user, message));
await ctx.Reply(components: _embeds.CreateAuthorMessageComponents(user, message));
return;
}

View file

@ -58,13 +58,19 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
var channel = await _cache.TryGetChannel(guildId, evt.ChannelId); // todo: is this correct for message update?
if (channel == null)
throw new Exception("could not find self channel in MessageEdited event");
{
_logger.Warning("could not find self channel in MessageEdited event");
return;
}
if (!DiscordUtils.IsValidGuildChannel(channel))
return;
var rootChannel = await _cache.GetRootChannel(guildId, channel.Id);
var guild = await _cache.TryGetGuild(channel.GuildId!.Value);
if (guild == null)
throw new Exception("could not find self guild in MessageEdited event");
{
_logger.Warning("could not find self guild in MessageEdited event");
return;
}
var lastMessage = (await _lastMessageCache.GetLastMessage(evt.GuildId.HasValue ? evt.GuildId.Value ?? 0 : 0, evt.ChannelId))?.Current;
// Only react to the last message in the channel

View file

@ -45,9 +45,16 @@ public class Init
opts.Dsn = services.Resolve<CoreConfig>().SentryUrl ?? "";
opts.Release = BuildInfoService.FullVersion;
opts.AutoSessionTracking = true;
// opts.DisableTaskUnobservedTaskExceptionCapture();
opts.DisableUnobservedTaskExceptionCapture();
});
TaskScheduler.UnobservedTaskException += (_, e) =>
{
foreach (var inner in e.Exception.Flatten().InnerExceptions)
SentrySdk.CaptureException(inner);
e.SetObserved();
};
var config = services.Resolve<BotConfig>();
var coreConfig = services.Resolve<CoreConfig>();

View file

@ -1004,7 +1004,7 @@ public class EmbedService
return eb.Build();
}
public async Task<MessageComponent[]> CreateAuthorMessageComponents(User? user, FullMessage msg)
public MessageComponent[] CreateAuthorMessageComponents(User? user, FullMessage msg)
{
MessageComponent authorInfo;
var author = user != null
@ -1049,7 +1049,7 @@ public class EmbedService
authorInfo,
]
};
return (
return
[
new MessageComponent()
{
@ -1057,8 +1057,7 @@ public class EmbedService
Content = user != null ? $"{user.Mention()} ({user.Id})" : $"*(deleted user {msg.Message.Sender})*"
},
container
]
);
];
}
public async Task<MessageComponent[]> CreateCommandMessageInfoMessageComponents(Core.CommandMessage msg, bool showContent)

View file

@ -32,7 +32,7 @@ public class LastMessageCacheService
public async Task<CacheEntry?> GetLastMessage(ulong guild, ulong channel)
{
if (_maybeHttp is HttpDiscordCache)
return await (_maybeHttp as HttpDiscordCache).GetLastMessage<CacheEntry>(guild, channel);
return await (_maybeHttp as HttpDiscordCache)!.GetLastMessage<CacheEntry>(guild, channel);
return _cache.TryGetValue(channel, out var message) ? message : null;
}