Add non-recursive trace to empty catch blocks in `StructuredTraceSource.TraceScope` by euxaristia · Pull Request #27622 · PowerShell/PowerShell · GitHub
Skip to content

Add non-recursive trace to empty catch blocks in StructuredTraceSource.TraceScope#27622

Open
euxaristia wants to merge 1 commit into
PowerShell:masterfrom
euxaristia:fix/empty-catch-trace-source
Open

Add non-recursive trace to empty catch blocks in StructuredTraceSource.TraceScope#27622
euxaristia wants to merge 1 commit into
PowerShell:masterfrom
euxaristia:fix/empty-catch-trace-source

Conversation

@euxaristia

Copy link
Copy Markdown

PR Summary

Add System.Diagnostics.Trace.WriteLine calls to three empty catch blocks in StructuredTraceSource.TraceScope methods that were silently swallowing exceptions from the ScopeTracer constructor.

PR Context

The TraceScope overloads contained empty catch blocks that caught all exceptions from the ScopeTracer constructor. While the original intent was to ensure trace methods never throw, silently swallowing all exceptions hides infrastructure failures. Using System.Diagnostics.Trace.WriteLine (which bypasses PSTraceSource) provides diagnostics without risk of recursion.

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

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

This PR improves diagnostics in StructuredTraceSource.TraceScope by adding non-recursive System.Diagnostics.Trace.WriteLine output in previously empty catch blocks that swallowed exceptions from ScopeTracer construction.

Changes:

  • Replaced three empty catch { } blocks in TraceScope overloads with catch (Exception e) blocks.
  • Added System.Diagnostics.Trace.WriteLine(...) calls to emit a diagnostic message when ScopeTracer construction fails.

Comment on lines +440 to +443
Comment on lines +457 to +460
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine("ScopeTracer(string,object) threw: " + e.Message);
}
Comment on lines +474 to +477
…ce.TraceScope`

The `TraceScope` methods contained empty catch blocks that silently
swallowed exceptions from the `ScopeTracer` constructor. Use
`System.Diagnostics.Trace.WriteLine` for diagnostics since the class's
own trace methods would cause recursion here.
@euxaristia euxaristia force-pushed the fix/empty-catch-trace-source branch from 5134f29 to ab756f9 Compare June 21, 2026 23:52
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