From 497918eddadafdac9cd7db47bb103da1dfdf4b56 Mon Sep 17 00:00:00 2001 From: Christopher Felegy Date: Mon, 31 Dec 2018 13:36:30 -0500 Subject: [PATCH] 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. --- src/Discord.Net.Commands/CommandService.cs | 2 +- src/Discord.Net.Commands/Info/CommandInfo.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index c36aec4a5..94f2636ee 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -605,7 +605,7 @@ namespace Discord.Commands //If we get this far, at least one parse was successful. Execute the most likely overload. var chosenOverload = successfulParses[0]; 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); return result; } diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs index 42e42aa18..a8aa3157c 100644 --- a/src/Discord.Net.Commands/Info/CommandInfo.cs +++ b/src/Discord.Net.Commands/Info/CommandInfo.cs @@ -274,6 +274,7 @@ namespace Discord.Commands await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false); var result = ExecuteResult.FromError(ex); + await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false); if (Module.Service._throwOnError) {