mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix(bot): clean up "not found in cache" errors in sentry
This commit is contained in:
parent
63777bf810
commit
d74a6678c8
3 changed files with 22 additions and 2 deletions
|
|
@ -9,14 +9,14 @@ public static class CacheExtensions
|
|||
public static async Task<Guild> GetGuild(this IDiscordCache cache, ulong guildId)
|
||||
{
|
||||
if (!(await cache.TryGetGuild(guildId) is Guild guild))
|
||||
throw new KeyNotFoundException($"Guild {guildId} not found in cache");
|
||||
throw new NotFoundInCacheException(guildId, "guild");
|
||||
return guild;
|
||||
}
|
||||
|
||||
public static async Task<Channel> GetChannel(this IDiscordCache cache, ulong guildId, ulong channelId)
|
||||
{
|
||||
if (!(await cache.TryGetChannel(guildId, channelId) is Channel channel))
|
||||
throw new KeyNotFoundException($"Channel {channelId} not found in cache");
|
||||
throw new NotFoundInCacheException(channelId, "channel");
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
|
@ -55,3 +55,15 @@ public static class CacheExtensions
|
|||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
public class NotFoundInCacheException: Exception
|
||||
{
|
||||
public ulong EntityId { get; init; }
|
||||
public string EntityType { get; init; }
|
||||
|
||||
public NotFoundInCacheException(ulong id, string type) : base("expected entity in discord cache but was not found")
|
||||
{
|
||||
EntityId = id;
|
||||
EntityType = type;
|
||||
}
|
||||
}
|
||||
|
|
@ -213,6 +213,13 @@ public class Bot
|
|||
{
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.BotErrors, exc.GetType().FullName);
|
||||
|
||||
if (exc is Myriad.Extensions.NotFoundInCacheException ce)
|
||||
{
|
||||
var scope = serviceScope.Resolve<Scope>();
|
||||
scope.SetTag("entity.id", ce.EntityId.ToString());
|
||||
scope.SetTag("entity.type", ce.EntityType);
|
||||
}
|
||||
|
||||
// Make this beforehand so we can access the event ID for logging
|
||||
var sentryEvent = new SentryEvent(exc);
|
||||
|
||||
|
|
|
|||
|
|
@ -949,6 +949,7 @@
|
|||
"Microsoft.AspNetCore.Mvc.Versioning": "[5.1.0, )",
|
||||
"Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer": "[5.1.0, )",
|
||||
"PluralKit.Core": "[1.0.0, )",
|
||||
"Sentry": "[4.13.0, )",
|
||||
"Serilog.AspNetCore": "[9.0.0, )"
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue