Handle command failures consistently without stack traces - #330
Merged
Conversation
Add a root invocation boundary that reports concise command errors without stack traces while preserving registry diagnostics and cancellation behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Root-level OperationCanceledException handling currently suppresses diagnostics even when cancellation wasn’t actually requested, which can hide failure messages and conflicts with the stated behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR standardizes command-failure handling at the CLI root invocation boundary so expected user errors (e.g., invalid settings names) no longer surface full .NET stack traces, while preserving existing registry-specific error messaging behavior.
Changes:
- Routes
Programexecution through a newCommandHelper.InvokeRootCommandwrapper that disables System.CommandLine’s default exception handler and emits concise diagnostics to stderr with exit code1. - Hardens error rendering in
CommandHelper.WriteErrorto always restore console color viatry/finally. - Adds/extends tests covering concise failure output for invalid settings, representative registry failures, and cancellation behaviors.
File summaries
| File | Description |
|---|---|
| src/Valleysoft.Dredge/Program.cs | Switches root invocation to a centralized wrapper for consistent error handling. |
| src/Valleysoft.Dredge/CommandHelper.cs | Introduces root invocation boundary and refines error output behavior. |
| src/Valleysoft.Dredge.Tests/RegistryIntegrationTests.cs | Asserts registry failures do not leak stack traces/type names. |
| src/Valleysoft.Dredge.Tests/CommandCancellationTests.cs | Adds coverage for root-level failures and cancellation scenarios. |
| src/Valleysoft.Dredge.Tests/CliProcessTests.cs | Adds end-to-end process test for invalid settings producing concise stderr. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Only suppress root cancellation diagnostics when the exception carries a canceled token, and cover both cancellation paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some commands relied on System.CommandLine's default exception handler, which exposed full .NET stack traces for expected user errors such as unknown setting names.
Summary
Testing
dotnet test --no-restore -v minimal -c Release --filter "Category!=Integration"(984 passed across .NET 9 and .NET 10)Fixes: #313