Skip to content

Add trace logging to empty catch blocks in CommandDiscovery#27621

Open
euxaristia wants to merge 2 commits into
PowerShell:masterfrom
euxaristia:fix/empty-catch-command-discovery
Open

Add trace logging to empty catch blocks in CommandDiscovery#27621
euxaristia wants to merge 2 commits into
PowerShell:masterfrom
euxaristia:fix/empty-catch-command-discovery

Conversation

@euxaristia

Copy link
Copy Markdown

PR Summary

Add discoveryTracer.TraceError() calls to two empty catch blocks in CommandDiscovery.LookupCommandInfo that were silently swallowing all exceptions.

PR Context

Two catch blocks — one for PreCommandLookupAction invoker exceptions and one for module auto-discovery exceptions — were catching Exception with an empty body. This hides failures from diagnostic traces and makes debugging difficult. Both handlers are intentional (external event handlers should not crash command lookup, and module discovery failures should degrade gracefully), but the exceptions should still be logged when tracing is enabled.

PR Checklist

  • PR title is meaningful and in present tense, imperative mood
  • Changes are summarized in the PR description
  • All files have the Microsoft copyright header
  • Ready for review -- this is not a Draft PR
  • Breaking changes: None
  • User-facing changes: No
  • Testing: N/A -- logging only, no behavioral change

Two catch blocks in `LookupCommandInfo` were silently swallowing all exceptions from `PreCommandLookupAction` invocations and module auto-discovery. Log these failures via `discoveryTracer` so they are visible in diagnostic traces.
Copilot AI review requested due to automatic review settings June 21, 2026 22:08
@euxaristia
euxaristia requested a review from a team as a code owner June 21, 2026 22:08

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.

Pull request overview

Adds trace logging in CommandDiscovery to avoid silently swallowing exceptions during command lookup, improving diagnosability when tracing is enabled.

Changes:

  • Log exceptions thrown by PreCommandLookupAction instead of silently ignoring them.
  • Log exceptions thrown during module auto-discovery instead of silently ignoring them.

catch (Exception)
catch (Exception e)
{
discoveryTracer.TraceError("PreCommandLookupAction threw: {0}", e.Message);
catch (Exception)
catch (Exception e)
{
discoveryTracer.TraceError("Module auto-discovery threw: {0}", e.Message);
Use the exception object directly (which calls ToString for type+message+stack) instead of just e.Message, and include the command name being looked up.
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.

2 participants