dotnet/yarp · error · ArgumentException
Expected additional args.
Error message
Expected additional args.
What it means
Thrown by the SampleClient's CommandLineArgs.ParseRemainder when it is asked to parse a remainder that contains zero tokens. In the shipped parser this branch is effectively unreachable because ParseRemainder is only called when i < args.Length, so the slice always has length >= 1; it exists as a defensive guard for the 'a scenario name is required' intent.
Source
Thrown at testassets/TestClient/CommandLineArgs.cs:57
case "--target":
case "-t":
result.Target = args[++i];
break;
}
}
if (i < args.Length)
{
return ParseRemainder(result, args.AsSpan().Slice(i));
}
return result;
static CommandLineArgs ParseRemainder(CommandLineArgs result, Span<string> remainder)
{
if (remainder.Length == 0)
{
throw new ArgumentException("Expected additional args.");
}
if (remainder.Length > 1)
{
throw new ArgumentException($"Unexpected arg '{remainder[1]}'.");
}
result.Scenario = remainder[0];
return result;
}
}
public static void ShowHelp()
{
Console.WriteLine("ReverseProxy SampleClient.\n");
Console.WriteLine("--scenario <name>, -s <name>: Runs only the specified scenario.");
Console.WriteLine(
"--target <uri>, -t <uri>: Sets the target uri. By default, 'https://localhost:1443/' is used.");View on GitHub (pinned to bd11867bee)
Solutions
- Pass a scenario name, e.g. `--scenario Http2PostExpectContinueScenario` or as a single positional argument.
- If you modified CommandLineArgs, ensure ParseRemainder is only invoked with a non-empty remainder, or remove the now-dead branch.
Defensive patterns
Strategy: validation
Validate before calling
// Guard the CLI entry point: require a scenario before running.
var args2 = CommandLineArgs.Parse(args);
if (string.IsNullOrEmpty(args2.Scenario)) {
CommandLineArgs.ShowHelp();
return 1;
} Prevention
- Always invoke the SampleClient with an explicit --scenario/-s value.
- If you refactor the parser, keep the invariant that ParseRemainder only runs on a non-empty remainder.
- Treat this branch as documentation of intent; cover it with a direct unit test if you depend on it.
When it happens
Trigger: Conceptually: invoking the SampleClient in a way that reaches ParseRemainder with an empty remainder. In practice this requires an internal caller change; the normal CLI path cannot trigger it because the loop only delegates when there is at least one remaining token.
Common situations: Editing the parser and removing the guard that ensures remainder.Length > 0 before calling ParseRemainder; calling ParseRemainder directly from a test with an empty span.
Related errors
- Unexpected arg '{remainder[1]}'.
- Expected status 409 Conflict!
- Expected status 101 Switching Protocols!
- Read {read} bytes, expected 0 after sending Goodbye.
- Read {read} bytes, expected 1.
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/d5012aa6aaf54752.
Report an issue: GitHub.