From 044a4d99b8833144d70daecb5a76f4b51525e99b Mon Sep 17 00:00:00 2001 From: Cenngo Date: Wed, 23 Nov 2022 23:45:52 +0300 Subject: [PATCH] log command execution exceptions in wrapped obj --- .../Info/Commands/CommandInfo.cs | 1 + .../InteractionException.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/Discord.Net.Interactions/InteractionException.cs diff --git a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs index ea5ded11c..78f0b6000 100644 --- a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs @@ -200,6 +200,7 @@ namespace Discord.Interactions while (ex is TargetInvocationException) ex = ex.InnerException; + var interactionException = new InteractionException(this, context, ex); await Module.CommandService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); var result = ExecuteResult.FromError(ex); diff --git a/src/Discord.Net.Interactions/InteractionException.cs b/src/Discord.Net.Interactions/InteractionException.cs new file mode 100644 index 000000000..c1d4c3f45 --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Discord.Interactions +{ + public class InteractionException : Exception + { + public ICommandInfo CommandInfo { get; } + public IInteractionContext InteractionContext { get; } + + public InteractionException(ICommandInfo commandInfo, IInteractionContext context, Exception exception) + : base($"Error occurred executing {commandInfo}.", exception) + { + CommandInfo = commandInfo; + InteractionContext = context; + } + } +}