feature: Provide ParameterInfo with error ParseResult (#1355)

Currently, when handling parsing errors, there is no way to know what
parameter caused the error. This change makes the CommandParser create
the parsing error with the current parameter info when ParseAsync()
fails. It is then available through the ErrorParameter of the
ParseResult.
This commit is contained in:
Adam Gauthier
2019-09-08 18:06:19 -04:00
committed by Christopher F
parent b00da3d73c
commit 3755a027b3
2 changed files with 28 additions and 14 deletions

View File

@@ -103,7 +103,7 @@ namespace Discord.Commands
argBuilder.Append(c);
continue;
}
if (IsOpenQuote(aliasMap, c))
{
curPart = ParserPart.QuotedParameter;
@@ -136,7 +136,7 @@ namespace Discord.Commands
else
argBuilder.Append(c);
}
if (argString != null)
{
if (curParam == null)
@@ -149,7 +149,7 @@ namespace Discord.Commands
var typeReaderResult = await curParam.ParseAsync(context, argString, services).ConfigureAwait(false);
if (!typeReaderResult.IsSuccess && typeReaderResult.Error != CommandError.MultipleMatches)
return ParseResult.FromError(typeReaderResult);
return ParseResult.FromError(typeReaderResult, curParam);
if (curParam.IsMultiple)
{
@@ -172,7 +172,7 @@ namespace Discord.Commands
{
var typeReaderResult = await curParam.ParseAsync(context, argBuilder.ToString(), services).ConfigureAwait(false);
if (!typeReaderResult.IsSuccess)
return ParseResult.FromError(typeReaderResult);
return ParseResult.FromError(typeReaderResult, curParam);
argList.Add(typeReaderResult);
}
@@ -180,7 +180,7 @@ namespace Discord.Commands
return ParseResult.FromError(CommandError.ParseFailed, "Input text may not end on an incomplete escape.");
if (curPart == ParserPart.QuotedParameter)
return ParseResult.FromError(CommandError.ParseFailed, "A quoted parameter is incomplete.");
//Add missing optionals
for (int i = argList.Count; i < command.Parameters.Count; i++)
{
@@ -191,7 +191,7 @@ namespace Discord.Commands
return ParseResult.FromError(CommandError.BadArgCount, "The input text has too few parameters.");
argList.Add(TypeReaderResult.FromSuccess(param.DefaultValue));
}
return ParseResult.FromSuccess(argList.ToImmutable(), paramList.ToImmutable());
}
}