Skip to content

Compact error output, fix four-dash bug, improve error messages#1550

Merged
garrytrinder merged 5 commits intomainfrom
copilot/improve-error-messages-formatting
Feb 26, 2026
Merged

Compact error output, fix four-dash bug, improve error messages#1550
garrytrinder merged 5 commits intomainfrom
copilot/improve-error-messages-formatting

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

Parse errors dump 40+ lines of help text after a one-line error, burying the actual problem. The JWT signing-key validator produces ----signing-key (four dashes) because .Name already includes the -- prefix.

Changes

  • Suppress help on errors: Set ParseErrorAction.ShowHelp = false when the parse result action is a ParseErrorAction — uses the built-in System.CommandLine beta5 API rather than custom middleware
  • Fix four-dash bug in JwtCommand.cs: $"'--{option.Name}'"$"'{option.Name}'" since Name already returns --signing-key
  • Consistent, actionable error messages across all validators — quote invalid values, include valid alternatives or examples:
# Before
not-an-ip is not a valid IP address
[... 40 lines of help ...]

# After
'not-an-ip' is not a valid IP address. Example: 127.0.0.1
Validator Error format
IP address 'X' is not a valid IP address. Example: 127.0.0.1
Log level 'X' is not a valid log level. Allowed values: Trace, Debug, …
Timeout 'X' is not a valid timeout value. Specify a positive integer (in seconds).
Config file Configuration file 'X' does not exist. Check the file path and try again.
Log-for 'X' is not a valid log-for value. Allowed values: Human, Machine

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/dotnet dotnet exec DevProxy/bin/Debug/net10.0/devproxy.dll --ip-address not-an-ip (dns block)
    • Triggering command: /usr/bin/dotnet dotnet exec DevProxy/bin/Debug/net10.0/devproxy.dll jwt create --signing-key short (dns block)
    • Triggering command: /usr/bin/dotnet dotnet exec DevProxy/bin/Debug/net10.0/devproxy.dll --ip-address not-an-ip 0 -j ACCEPT (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Improve error messages: compact output and fix formatting bugs</issue_title>
<issue_description>Parent: #1534

Problem

When a validation error occurs, the CLI prints a one-line error message followed by the entire help text (40+ lines). For example:

not-an-ip is not a valid IP address

Description:
  Start Dev Proxy

Usage:
  devproxy [command] [options]

Options:
  [... 20+ lines of options ...]

Commands:
  [... 6+ lines of commands ...]

This creates two problems for agents:

  1. The actual error is buried — an agent scanning output must find the needle in the haystack
  2. Parsing the error requires distinguishing the error line from the help text that follows

Additionally, some error messages have formatting bugs. The JWT signing-key validator produces:

Requires option '----signing-key' to be at least 32 characters

Four dashes instead of two, because the code uses $"Requires option '--{jwtSigningKeyOption.Name}'" but .Name already includes the -- prefix.

Rationale

Agents self-correct from error messages. A good error message lets the agent fix its input and retry without re-reading help. Dumping 40 lines of help text defeats this — the agent has to parse all of it to find the one-line error. Malformed option names in error messages (like ----signing-key) prevent agents from mapping the error back to the correct flag.

Proposed solution

1. Compact error output

On validation errors, print only the error and a pointer to help:

Error: "not-an-ip" is not a valid IP address. Example: 127.0.0.1
Run 'devproxy --help' for usage information.

This may require customizing System.CommandLine's error handling behavior.

2. Actionable error messages

Where possible, include the invalid value AND valid alternatives:

  • Error: Invalid log level "verbose". Allowed values: Trace, Debug, Information, Warning, Error, Critical, None
  • Error: Invalid environment variable format "FOO". Expected format: name=value

The existing validators already include valid alternatives in some cases — this is about consistency across all validators.

3. Fix the four-dash bug

In JwtCommand.cs, the signing-key validator does:

input.AddError($"Requires option '--{jwtSigningKeyOption.Name}' to be at least 32 characters");

jwtSigningKeyOption.Name returns --signing-key (with dashes). Fix: use the name without the prefix, or reference the option differently.

Affected code

  • DevProxy/Commands/DevProxyCommand.cs — all validators
  • DevProxy/Commands/JwtCommand.cs — signing-key validator (four-dash bug)
  • Potentially System.CommandLine middleware configuration
    </issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

- 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>
Copilot AI changed the title [WIP] Improve error messages for validation and formatting issues Compact error output, fix four-dash bug, improve error messages Feb 25, 2026
@waldekmastykarz waldekmastykarz marked this pull request as ready for review February 25, 2026 13:10
@waldekmastykarz waldekmastykarz requested a review from a team as a code owner February 25, 2026 13:10
Copilot AI review requested due to automatic review settings February 25, 2026 13:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make Dev Proxy CLI parse/validation failures more readable by suppressing automatic help output on parse errors and by standardizing validator error messages to be more actionable.

Changes:

  • Suppress System.CommandLine help text on parse errors by setting ParseErrorAction.ShowHelp = false.
  • Standardize several option validator error messages (config file, IP address, log level, timeout, log-for) to quote invalid input and provide guidance.
  • Adjust JWT signing-key validator error formatting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
DevProxy/Commands/DevProxyCommand.cs Suppresses help output on parse errors and improves several validator error messages for consistency/actionability.
DevProxy/Commands/JwtCommand.cs Updates the signing-key validator error message formatting.

Copy link
Contributor

@garrytrinder garrytrinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested: builds clean. Help text suppressed on validation errors. Four-dash bug fixed (--signing-key). All error messages are actionable with quoted values and valid alternatives (IP, log level, timeout, config file, output format). Exit code 2 for validation errors. LGTM.

@garrytrinder garrytrinder enabled auto-merge (squash) February 26, 2026 12:01
@garrytrinder garrytrinder merged commit 64f4277 into main Feb 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messages: compact output and fix formatting bugs

4 participants