Skip to content

Trace-Command -Name TypeConversion might not unwind the tracing scope stack after a failed cast #28035

Description

@GeeLaw

Prerequisites

Steps to reproduce

Trace-Command -Name TypeConversion -PSHost -Expression { [int]'123' };
Trace-Command -Name TypeConversion -PSHost -Expression { [int]'123' };

Trace-Command -Name TypeConversion -PSHost -Expression { [int]'Hello' };
Trace-Command -Name TypeConversion -PSHost -Expression { [int]'Hello' };

Expected behavior

DEBUG: 2026-09-19 19:37:39.6858 TypeConversion Information: 0 : Converting to integer.
123
DEBUG: 2026-09-19 19:37:39.6900 TypeConversion Information: 0 : Converting to integer.
123
DEBUG: 2026-09-19 19:37:39.6912 TypeConversion Information: 0 : Converting to integer.
DEBUG: 2026-09-19 19:37:39.6918 TypeConversion Information: 0 : Exception converting to integer: "The input string 'Hello' was not in a correct format.".

<...>

InvalidArgument:
Line |
   4 |  … ce-Command -Name TypeConversion -PSHost -Expression { [int]'Hello' };
     |                                                          ~~~~~~~~~~~~
     | Cannot convert value "Hello" to type "System.Int32". Error: "The input string 'Hello' was not in a correct format."

DEBUG: 2026-09-19 19:37:39.7870 TypeConversion Information: 0 : Converting to integer.

<...>

Actual behavior

The last tracing output starts with high indentation.

<...>

DEBUG: 2026-09-19 19:37:39.7870 TypeConversion Information: 0 :                         Converting to integer.

<...>

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.6
PSEdition                      Core
GitCommitId                    7.6.6
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Note how after the error, the messages are highly indented.

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions