Skip to content

Commit

Permalink
fix: raise CommandExecuted on async errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
foxbot committed Dec 31, 2018
1 parent 552f34c commit 497918e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Discord.Net.Commands/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ float CalculateScore(CommandMatch match, ParseResult parseResult)
//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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Discord.Net.Commands/Info/CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private async Task<IResult> ExecuteInternalAsync(ICommandContext context, object
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)
{
Expand Down

0 comments on commit 497918e

Please sign in to comment.