Skip to content

Commit 64f4277

Browse files
Copilotwaldekmastykarzgarrytrinder
authored
Compact error output, fix four-dash bug, improve error messages (#1550)
* Initial plan * Compact error output, fix four-dash bug, and improve error messages - Suppress help text on parse errors using ParseErrorAction.ShowHelp = false - Fix four-dash bug in JwtCommand.cs: jwtSigningKeyOption.Name already includes '--' - Improve error messages across all validators for consistency: - Wrap invalid values in quotes for clarity - Add actionable hints (examples, allowed values) - Use consistent formatting pattern Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> Co-authored-by: Waldek Mastykarz <waldek@mastykarz.nl> Co-authored-by: Garry Trinder <garry@trinder365.co.uk>
1 parent 389af3c commit 64f4277

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

DevProxy/Commands/DevProxyCommand.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using DevProxy.Abstractions.Utils;
44
using System.CommandLine;
55
using System.CommandLine.Help;
6+
using System.CommandLine.Invocation;
67
using System.CommandLine.Parsing;
78
using System.Globalization;
89

@@ -218,6 +219,12 @@ public async Task<int> InvokeAsync(string[] args, WebApplication app)
218219
var parseResult = IsStdioCommand
219220
? StdioCommand.ParseStdioArgs(this, args)
220221
: Parse(args);
222+
223+
if (parseResult.Action is ParseErrorAction parseErrorAction)
224+
{
225+
parseErrorAction.ShowHelp = false;
226+
}
227+
221228
var exitCode = await parseResult.InvokeAsync(app.Lifetime.ApplicationStopping);
222229

223230
// Return exit code 2 for input validation and parse errors to distinguish
@@ -300,7 +307,7 @@ private void ConfigureCommand()
300307

301308
if (!File.Exists(filePath))
302309
{
303-
input.AddError($"Configuration file {filePath} does not exist");
310+
input.AddError($"Configuration file '{filePath}' does not exist. Check the file path and try again.");
304311
}
305312
});
306313

@@ -313,7 +320,7 @@ private void ConfigureCommand()
313320
{
314321
if (!System.Net.IPAddress.TryParse(input.Tokens[0].Value, out _))
315322
{
316-
input.AddError($"{input.Tokens[0].Value} is not a valid IP address");
323+
input.AddError($"'{input.Tokens[0].Value}' is not a valid IP address. Example: 127.0.0.1");
317324
}
318325
});
319326

@@ -335,7 +342,7 @@ private void ConfigureCommand()
335342
{
336343
if (!Enum.TryParse<LogLevel>(input.Tokens[0].Value, true, out _))
337344
{
338-
input.AddError($"{input.Tokens[0].Value} is not a valid log level. Allowed values are: {string.Join(", ", Enum.GetNames<LogLevel>())}");
345+
input.AddError($"'{input.Tokens[0].Value}' is not a valid log level. Allowed values: {string.Join(", ", Enum.GetNames<LogLevel>())}");
339346
}
340347
});
341348

@@ -417,7 +424,7 @@ private void ConfigureCommand()
417424
{
418425
if (!long.TryParse(input.Tokens[0].Value, out var timeoutInput) || timeoutInput < 1)
419426
{
420-
input.AddError($"{input.Tokens[0].Value} is not valid as a timeout value");
427+
input.AddError($"'{input.Tokens[0].Value}' is not a valid timeout value. Specify a positive integer (in seconds).");
421428
}
422429
}
423430
catch (InvalidOperationException ex)
@@ -474,7 +481,7 @@ private void ConfigureCommand()
474481
}
475482
if (!Enum.TryParse<OutputFormat>(input.Tokens[0].Value, true, out _))
476483
{
477-
input.AddError($"{input.Tokens[0].Value} is not a valid output format. Allowed values are: {string.Join(", ", Enum.GetNames<OutputFormat>())}");
484+
input.AddError($"'{input.Tokens[0].Value}' is not a valid output format. Allowed values: {string.Join(", ", Enum.GetNames<OutputFormat>())}");
478485
}
479486
});
480487

DevProxy/Commands/JwtCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void ConfigureCommand()
9494
var value = input.GetValue(jwtSigningKeyOption);
9595
if (string.IsNullOrWhiteSpace(value) || value.Length < 32)
9696
{
97-
input.AddError($"Requires option '--{jwtSigningKeyOption.Name}' to be at least 32 characters");
97+
input.AddError($"Requires option '{jwtSigningKeyOption.Name}' to be at least 32 characters");
9898
}
9999
}
100100
catch (InvalidOperationException ex)

0 commit comments

Comments
 (0)