Skip to content

Surface unhandled exceptions in CLI and TestHarness#62

Open
kyurkchyan wants to merge 1 commit into
masterfrom
fix/surface-cli-exceptions
Open

Surface unhandled exceptions in CLI and TestHarness#62
kyurkchyan wants to merge 1 commit into
masterfrom
fix/surface-cli-exceptions

Conversation

@kyurkchyan
Copy link
Copy Markdown
Owner

@kyurkchyan kyurkchyan commented May 1, 2026

Summary

  • The outer catch (Exception) in both CommandExecutionService files (CLI and TestHarness) silently swallowed exceptions, setting exit code 1 with no output. Commands like generate-dlq failed without any visible error.
  • BaseCommandHandler only caught AuthenticationFailedException, ServiceBusException, and OperationCanceledException — anything else (e.g. MessagingEntityNotFoundException, NREs, argument exceptions) bubbled up to the silent outer catch.

Fix

  • CommandExecutionService (both projects) now prints ex.GetType().Name, ex.Message, and full ex.ToString() to stderr in red before setting exit code 1.
  • BaseCommandHandler (both projects) gained a generic catch (Exception) so expected handler errors get formatted via IConsoleOutput.Error, with the full stack trace shown when --verbose is passed.
  • Two-layer approach: BaseCommandHandler produces clean user-facing messages; CommandExecutionService is the safety net for failures outside a handler (DI resolution, parser, etc.).

Test plan

  • Re-run dotnet run --project src/ServiceBusToolset.TestHarness -- generate-dlq -n <bad-namespace> -q <bad-queue> -c 1 and confirm the auth/ServiceBus error is now visible.
  • Run a CLI command against an invalid queue and confirm the error is printed.
  • Verify a successful run still exits 0 with no extra output.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and reporting with detailed exception information, messages, and stack traces displayed when unexpected errors occur during command execution across the application.
    • Error messages are now prominently displayed in red-colored text for enhanced visibility and clarity during failures.
    • Added verbose logging mode to display complete diagnostic details for troubleshooting purposes when needed.

The outer catch in CommandExecutionService silently swallowed any exception
not handled by BaseCommandHandler's specific catches (auth, ServiceBus,
cancellation), so failures like missing queues or unexpected errors exited
with code 1 and no output. Print the exception to stderr in the safety net,
and add a generic catch in BaseCommandHandler so handler errors get
formatted via IConsoleOutput with stack traces under --verbose.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1159e23d-1a08-4dc8-91bc-41d5fac6e11e

📥 Commits

Reviewing files that changed from the base of the PR and between 7105929 and ba2963d.

📒 Files selected for processing (4)
  • src/ServiceBusToolset.CLI/CommandExecutionService.cs
  • src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs
  • src/ServiceBusToolset.TestHarness/CommandExecutionService.cs
  • src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs

📝 Walkthrough

Walkthrough

This PR enhances error handling in CLI and TestHarness components by capturing exceptions and emitting detailed diagnostic information to standard error, including exception type, message, and stack traces with colored console output, while maintaining existing control flow and exit code behavior.

Changes

Cohort / File(s) Summary
CLI Command Execution
src/ServiceBusToolset.CLI/CommandExecutionService.cs, src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs
Enhanced exception handling to capture exception instance and output detailed error information (type, message, stack trace) to stderr with red console coloring; added catch-all handler for unexpected exceptions with verbose logging support.
Test Harness Command Execution
src/ServiceBusToolset.TestHarness/CommandExecutionService.cs, src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs
Parallel improvements to exception handling with captured exception details, colored stderr output, and conditional verbose stack trace logging; ensures error code 1 is returned on unhandled exceptions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Errors now sing in crimson bright,
Stack traces gleam before the night,
We catch them all, no stone unturned,
Each lesson learned, each exit earned!
Better errors make devs smile,
Worth debugging every mile! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Surface unhandled exceptions in CLI and TestHarness' directly and clearly summarizes the main objective of the PR—making unhandled exceptions visible by adding exception reporting to CommandExecutionService and BaseCommandHandler in both projects.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/surface-cli-exceptions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Summary

Summary
Generated on: 05/01/2026 - 09:42:40
Coverage date: 05/01/2026 - 09:42:37
Parser: MultiReport (2x Cobertura)
Assemblies: 1
Classes: 90
Files: 71
Line coverage: 64.4% (1350 of 2095)
Covered lines: 1350
Uncovered lines: 745
Coverable lines: 2095
Total lines: 4380
Branch coverage: 64.6% (621 of 960)
Covered branches: 621
Total branches: 960
Method coverage: Feature is only available for sponsors
Tag: 85_25209968407

Coverage

ServiceBusToolset.Application - 64.4%
Name Line Branch
ServiceBusToolset.Application 64.4% 64.6%
Mediator.AssemblyReference 0%
Mediator.Internals.CommandHandlerWrapper`2 0% 0%
Mediator.Internals.ContainerMetadata 0%
Mediator.Internals.NotificationHandlerWrapper`1 0% 0%
Mediator.Internals.QueryHandlerWrapper`2 0% 0%
Mediator.Internals.RequestHandlerWrapper`2 0% 0%
Mediator.Internals.StreamCommandHandlerWrapper`2 0% 0%
Mediator.Internals.StreamQueryHandlerWrapper`2 0% 0%
Mediator.Internals.StreamRequestHandlerWrapper`2 0% 0%
Mediator.Mediator 0% 0%
Mediator.MediatorOptions 0%
Mediator.MediatorOptionsAttribute 0%
Microsoft.Extensions.DependencyInjection.MediatorDependencyInjectionExtensi
ons
0% 0%
ServiceBusToolset.Application.ApplicationDependencyInjectionExtensions 0%
ServiceBusToolset.Application.Common.ServiceBus.Helpers.MessageFilters 100% 100%
ServiceBusToolset.Application.Common.ServiceBus.Helpers.MessageOperations 100% 96.1%
ServiceBusToolset.Application.Common.ServiceBus.Helpers.ReceiverFactory 100% 75%
ServiceBusToolset.Application.Common.ServiceBus.Helpers.StatisticsListCompa
rer`1
100% 100%
ServiceBusToolset.Application.Common.ServiceBus.Helpers.WildcardFilterHelpe
r
100% 100%
ServiceBusToolset.Application.Common.ServiceBus.Models.EntityTarget 100% 100%
ServiceBusToolset.Application.Common.ServiceBus.Models.FilteredMessageCount 100%
ServiceBusToolset.Application.Common.ServiceBus.Models.ServiceBusMessage 100%
ServiceBusToolset.Application.Common.ServiceBus.Reactive.ReactiveMessageCac
he`2
91.6% 83.3%
ServiceBusToolset.Application.Common.ServiceBus.Reactive.ResubmitTracker 100% 100%
ServiceBusToolset.Application.Common.ServiceBus.Serialization.MessageBodyDe
coder
80.9% 100%
ServiceBusToolset.Application.Common.ServiceBus.Serialization.MessageSerial
izer
100%
ServiceBusToolset.Application.DeadLetters.Common.CategorizationSchema 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.CategoryMerger 95.5% 92.8%
ServiceBusToolset.Application.DeadLetters.Common.CategoryMergeResult 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.CategoryPropertyRef 94.4% 91.6%
ServiceBusToolset.Application.DeadLetters.Common.CategoryPropertyResolver 81.8% 80.5%
ServiceBusToolset.Application.DeadLetters.Common.CategorySelection 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.CategorySelectionParser 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.DlqCategory 52.1% 33.3%
ServiceBusToolset.Application.DeadLetters.Common.DlqCategoryDisplay 100% 83.3%
ServiceBusToolset.Application.DeadLetters.Common.DlqCategoryKey 92.8% 95.4%
ServiceBusToolset.Application.DeadLetters.Common.DlqCategoryScanner 98.1% 95.4%
ServiceBusToolset.Application.DeadLetters.Common.DlqCategorySnapshot 80%
ServiceBusToolset.Application.DeadLetters.Common.DlqMessageService 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.DlqScanSession 96.8% 100%
ServiceBusToolset.Application.DeadLetters.Common.MessageResubmitHelper 100% 100%
ServiceBusToolset.Application.DeadLetters.Common.StreamDlqCommand 75%
ServiceBusToolset.Application.DeadLetters.Common.StreamDlqCommandHandler 86.6% 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Common.AppInsights.Ap
pInsightsService
0% 0%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Common.MessageDiagnos
tics
88.7% 91.6%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseBatchCommand 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseBatchCommandH
andler
100% 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseDlqCommand 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseDlqCommandHan
dler
100% 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseDlqResult 100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseFromCacheComm
and
100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.DiagnoseFromCacheComm
andHandler
100% 80%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Models.DependencyInfo 12.5%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Models.DiagnosticResu
lt
100%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Models.ExceptionInfo 33.3%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.Models.TraceInfo 0%
ServiceBusToolset.Application.DeadLetters.DiagnoseDlq.OperationInfo 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.CountDlqMessagesCommand 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.CountDlqMessagesHandler 100% 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DlqCountResult 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DlqDumpResult 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DumpDlqMessagesCommand 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DumpDlqMessagesCommandHan
dler
100% 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DumpFromCacheCommand 100%
ServiceBusToolset.Application.DeadLetters.DumpDlq.DumpFromCacheCommandHandl
er
100% 100%
ServiceBusToolset.Application.DeadLetters.PeekDlq.PeekDlqBatchCommand 100%
ServiceBusToolset.Application.DeadLetters.PeekDlq.PeekDlqBatchCommandHandle
r
89.8% 93.7%
ServiceBusToolset.Application.DeadLetters.PeekDlq.PeekDlqBatchResult 100%
ServiceBusToolset.Application.DeadLetters.PeekDlq.PeekedMessage 100%
ServiceBusToolset.Application.DeadLetters.PurgeDlq.PurgeDlqMessagesCommand 100%
ServiceBusToolset.Application.DeadLetters.PurgeDlq.PurgeDlqMessagesCommandH
andler
100% 97.7%
ServiceBusToolset.Application.DeadLetters.PurgeDlq.PurgeDlqResult 100%
ServiceBusToolset.Application.DeadLetters.PurgeDlq.PurgeFromCacheCommand 100%
ServiceBusToolset.Application.DeadLetters.PurgeDlq.PurgeFromCacheCommandHan
dler
91.8% 90.9%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.DlqResubmitSession 100% 100%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.ResubmitDlqMessagesCo
mmand
100%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.ResubmitDlqMessagesCo
mmandHandler
100% 98%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.ResubmitDlqResult 100%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.ResubmitFromCacheComm
and
100%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.ResubmitFromCacheComm
andHandler
97.5% 95.8%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.StreamDlqCategoriesCo
mmand
75%
ServiceBusToolset.Application.DeadLetters.ResubmitDlq.StreamDlqCategoriesCo
mmandHandler
87.8% 100%
ServiceBusToolset.Application.Queues.MonitorQueues.Models.QueueStatistics 100% 50%
ServiceBusToolset.Application.Queues.MonitorQueues.MonitorQueuesCommand 100%
ServiceBusToolset.Application.Queues.MonitorQueues.MonitorQueuesCommandHand
ler
100% 100%
ServiceBusToolset.Application.Queues.MonitorQueues.MonitorQueuesResult 100%
ServiceBusToolset.Application.Subscriptions.MonitorSubscriptions.Models.Sub
scriptionStatistics
100% 100%
ServiceBusToolset.Application.Subscriptions.MonitorSubscriptions.MonitorSub
scriptionsCommand
100%
ServiceBusToolset.Application.Subscriptions.MonitorSubscriptions.MonitorSub
scriptionsCommandHandler
100% 100%
ServiceBusToolset.Application.Subscriptions.MonitorSubscriptions.MonitorSub
scriptionsResult
100%

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.

1 participant