fix: raise CommandExecuted on async errors
This resolves #1224. Previously, raising CommandExecuted for errors was dependent on the failed result making it back to ExecuteAsync. This is not possible with async commands, which always pass back a succesful promise result, rather than their fulfilled result. This change moves the event invocation for exception'd ExecuteResults to their source, and excludes ExecuteResult from the late event invocation in CommandService#ExecuteAsync.
This commit is contained in:
@@ -605,7 +605,7 @@ namespace Discord.Commands
|
|||||||
//If we get this far, at least one parse was successful. Execute the most likely overload.
|
//If we get this far, at least one parse was successful. Execute the most likely overload.
|
||||||
var chosenOverload = successfulParses[0];
|
var chosenOverload = successfulParses[0];
|
||||||
var result = await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false);
|
var result = await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false);
|
||||||
if (!result.IsSuccess && !(result is RuntimeResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
|
if (!result.IsSuccess && !(result is RuntimeResult || result is ExecuteResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
|
||||||
await _commandExecutedEvent.InvokeAsync(chosenOverload.Key.Command, context, result);
|
await _commandExecutedEvent.InvokeAsync(chosenOverload.Key.Command, context, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ namespace Discord.Commands
|
|||||||
await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false);
|
await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false);
|
||||||
|
|
||||||
var result = ExecuteResult.FromError(ex);
|
var result = ExecuteResult.FromError(ex);
|
||||||
|
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false);
|
||||||
|
|
||||||
if (Module.Service._throwOnError)
|
if (Module.Service._throwOnError)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user