Fixed RunMode.Sync running Async. Added ThrowOnError option.

This commit is contained in:
RogueException
2017-03-18 21:38:28 -03:00
parent 83bd16f329
commit 3fb21e06c2
3 changed files with 11 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ namespace Discord.Commands
private readonly HashSet<ModuleInfo> _moduleDefs;
private readonly CommandMap _map;
internal readonly bool _caseSensitive;
internal readonly bool _caseSensitive, _throwOnError;
internal readonly char _separatorChar;
internal readonly RunMode _defaultRunMode;
internal readonly Logger _cmdLogger;
@@ -38,6 +38,7 @@ namespace Discord.Commands
public CommandService(CommandServiceConfig config)
{
_caseSensitive = config.CaseSensitiveCommands;
_throwOnError = config.ThrowOnError;
_separatorChar = config.SeparatorChar;
_defaultRunMode = config.DefaultRunMode;
if (_defaultRunMode == RunMode.Default)

View File

@@ -11,5 +11,11 @@
/// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary>
public LogSeverity LogLevel { get; set; } = LogSeverity.Info;
/// <summary>
/// Gets or sets whether RunMode.Sync commands should push exceptions up to the caller.
/// If false or an RunMode.Async command, exceptions are only reported in the Log event.
///</summary>
public bool ThrowOnError { get; set; } = true;
}
}

View File

@@ -140,7 +140,7 @@ namespace Discord.Commands
switch (RunMode)
{
case RunMode.Sync: //Always sync
var t1 = ExecuteAsyncInternal(context, args, map);
await ExecuteAsyncInternal(context, args, map).ConfigureAwait(false);
break;
case RunMode.Async: //Always async
var t2 = Task.Run(async () =>
@@ -168,7 +168,8 @@ namespace Discord.Commands
{
ex = new CommandException(this, context, ex);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
throw;
if (Module.Service._throwOnError)
throw;
}
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
}