Browse Source

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.
tags/2.0.1
Christopher Felegy 6 years ago
parent
commit
497918edda
2 changed files with 2 additions and 1 deletions
  1. +1
    -1
      src/Discord.Net.Commands/CommandService.cs
  2. +1
    -0
      src/Discord.Net.Commands/Info/CommandInfo.cs

+ 1
- 1
src/Discord.Net.Commands/CommandService.cs View File

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


+ 1
- 0
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -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)
{


Loading…
Cancel
Save