Skip to content

Handle command failures consistently without stack traces - #330

Merged
mthalman merged 2 commits into
mainfrom
mthalman-handle-command-failures
Sep 6, 2026
Merged

Handle command failures consistently without stack traces#330
mthalman merged 2 commits into
mainfrom
mthalman-handle-command-failures

Conversation

@mthalman

@mthalman mthalman commented Sep 6, 2026

Copy link
Copy Markdown
Owner

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

  • add a root invocation boundary that writes concise diagnostics to stderr and returns exit code 1
  • preserve registry-specific error and authentication guidance
  • retain silent process cancellation while treating unrelated cancellation exceptions as command failures
  • cover invalid settings, cancellation paths, and representative registry failures

Testing

  • dotnet test --no-restore -v minimal -c Release --filter "Category!=Integration" (984 passed across .NET 9 and .NET 10)
  • focused command failure and cancellation tests (42 passed across .NET 9 and .NET 10)
  • live-registry integration tests were not run locally because Docker was unavailable

Fixes: #313

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>
Copilot AI lite review requested due to automatic review settings September 6, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 Program execution through a new CommandHelper.InvokeRootCommand wrapper that disables System.CommandLine’s default exception handler and emits concise diagnostics to stderr with exit code 1.
  • Hardens error rendering in CommandHelper.WriteError to always restore console color via try/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.

Comment thread src/Valleysoft.Dredge/CommandHelper.cs Outdated
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>
@mthalman
mthalman merged commit 563eab0 into main Sep 6, 2026
3 checks passed
@mthalman
mthalman deleted the mthalman-handle-command-failures branch September 6, 2026 20:31
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.

Handle command failures consistently without stack traces

2 participants