Skip to content

Silently skips script execution if file ends with "<tab>´" #25709

Open

Description

@bnznrwn

Prerequisites

Steps to reproduce

a powershell script that ends with "[tab]´" silently returns without changing $LastExitCode and without any (Error) output, e.g.:

Write-Host "test"
Exit 123
junk
	`

(No newline after "´")

Expected behavior

PS> .\test.ps1
test
PS> $LastExitCode
123
PS>

Actual behavior

PS> $LastExitCode = 456
PS> .\test.ps1
PS>$LastExitCode
456
PS>

Error details

Exception             : 
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : You cannot call a method on a null-valued expression.
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvokeMethodOnNull
        InvocationInfo        : 
            ScriptLineNumber : 100
            OffsetInLine     : 17
            HistoryId        : 53
            Line             : $positionMessage = $myinv.PositionMessage.Split($newline)
                               
            Statement        : $positionMessage = $myinv.PositionMessage.Split($newline)
            PositionMessage  : At line:100 char:17
                               + …             $positionMessage = $myinv.PositionMessage.Split($newline) …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at Get-ConciseViewPositionMessage, <No file>: line 100
                                at <ScriptBlock>, <No file>: line 241
                                at <ScriptBlock>, <No file>: line 1
    TargetSite  : 
        Name          : CheckActionPreference
        DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : You cannot call a method on a null-valued expression.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  : 
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean eatExceptions)
CategoryInfo          : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
InvocationInfo        : 
    ScriptLineNumber : 100
    OffsetInLine     : 17
    HistoryId        : 53
    Line             : $positionMessage = $myinv.PositionMessage.Split($newline)
                       
    Statement        : $positionMessage = $myinv.PositionMessage.Split($newline)
    PositionMessage  : At line:100 char:17
                       + …             $positionMessage = $myinv.PositionMessage.Split($newline) …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at Get-ConciseViewPositionMessage, <No file>: line 100
                        at <ScriptBlock>, <No file>: line 241
                        at <ScriptBlock>, <No file>: line 1

Environment data

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

Visuals

No response

Activity

  1. added
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Jun 30, 2025
  2. 237dmitry commented on Jun 30, 2025

    @237dmitry

    In my environment it works as expected (pwsh 7.6.0.preview.4, Linux)

    Image

  3. mklement0 commented on Jun 30, 2025

    @mklement0
    Contributor

    237dmitry: the file has to end in a ` with no trailing newline.

    What's happening is that a parser error occurs - that is, the script file is considered malformed - but - and that is the real bug - it occurs quietly (can only be retrieved via $Error afterwards; visualize with Get-Error).

    The parser error is Incomplete string token and occurs because the ` acts as a line continuation, yet there's nothing to continue.

    The reason for the lack of error output is an exception occurring in the formatting of the error record with 'ConciseView' in effect (which is the default). The error does surface - albeit only partially - if you use $ErrorView = 'NormalView', for instance.

  4. 237dmitry commented on Jun 30, 2025

    @237dmitry

    the file has to end in a ` with no trailing newline.

    I thought TS especially marked where had to be tab. Otherwise, he probably would have mentioned additional conditions.

  5. mklement0 commented on Jun 30, 2025

    @mklement0
    Contributor

    Yes, a tab followed by a ` as the very last char. in the file (no trailing newline) - all these conditions are described in the original post (not sure what you mean by "TS").
    By contrast, your screenshot shows an LF newline instead of a ` as the last char.

    Curiously, if you replace the tab char. with a space, the parser error does surface.

  6. 237dmitry commented on Jun 30, 2025

    @237dmitry

    (not sure what you mean by "TS"

    Topic Starter

    It works without new line after the last string ( `t ) but not with `t`

  7. bnznrwn commented on Jun 30, 2025

    @bnznrwn
    Author

    Image

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