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;
|
||||
}
|
||||
|
||||
|
|
@ -54,4 +54,16 @@ public static class CacheExtensions
|
|||
if (parent == null) throw new Exception($"failed to find parent channel for thread {channelOrThread} in cache");
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue