Log InteractionCommand execution exceptions in Wrapped Exception (#2584)

* log command execution exceptions in wrapped obj

* actually log the wrapped exception

---------

Co-authored-by: Misha133 <mihagribkov133@gmail.com>
This commit is contained in:
Cenk Ergen
2024-01-17 01:06:29 +03:00
committed by GitHub
parent 5a8582cb6a
commit 0f0f3f7614
3 changed files with 22 additions and 3 deletions

View File

@@ -413,8 +413,9 @@ namespace Discord.Interactions.Builders
} }
catch (Exception ex) catch (Exception ex)
{ {
await commandService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); var interactionException = new InteractionException(commandInfo, context, ex);
return ExecuteResult.FromError(ex); await commandService._cmdLogger.ErrorAsync(interactionException).ConfigureAwait(false);
return ExecuteResult.FromError(interactionException);
} }
finally finally
{ {

View File

@@ -165,7 +165,8 @@ namespace Discord.Interactions
while (ex is TargetInvocationException) while (ex is TargetInvocationException)
ex = ex.InnerException; ex = ex.InnerException;
await Module.CommandService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); var interactionException = new InteractionException(this, context, ex);
await Module.CommandService._cmdLogger.ErrorAsync(interactionException).ConfigureAwait(false);
var result = ExecuteResult.FromError(ex); var result = ExecuteResult.FromError(ex);
await InvokeModuleEvent(context, result).ConfigureAwait(false); await InvokeModuleEvent(context, result).ConfigureAwait(false);

View File

@@ -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;
}
}
}