Skip to content

Commit

Permalink
Fix erroneous throw on remainder error
Browse files Browse the repository at this point in the history
  • Loading branch information
csmir committed Nov 15, 2024
1 parent 4d2cb48 commit 92d95ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/Commands/Core/ExecutionUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ public static async ValueTask<InvokeResult> HandleReturnType<T>(this CommandInfo
}
}

return InvokeResult.FromSuccess(command);
}
case IEnumerable @enum:
{
foreach (var item in @enum)
{
await consumer.Send(item);
}

return InvokeResult.FromSuccess(command);
}
case object obj:
Expand Down
14 changes: 11 additions & 3 deletions src/Commands/Reflection/Components/Impl/CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,19 @@ internal CommandInfo(

var (minLength, maxLength) = parameters.GetLength();

if (parameters.Any(x => x.Attributes.Contains<RemainderAttribute>(false)))
if (parameters.Any(x => x.IsRemainder))
{
if (parameters.Length > 1 && parameters[^1].IsRemainder)
for (var i = 0; i < parameters.Length; i++)
{
ThrowHelpers.ThrowInvalidOperation($"{nameof(RemainderAttribute)} can only exist on the last parameter of a command signature.");
var parameter = parameters[i];

if (parameter.IsRemainder)
{
if (i != parameters.Length - 1)
{
ThrowHelpers.ThrowInvalidOperation($"{nameof(RemainderAttribute)} can only exist on the last parameter of a command signature.");
}
}
}
}

Expand Down

0 comments on commit 92d95ab

Please sign in to comment.