Repository navigation
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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 1Environment 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.0Visuals
No response
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Activity
237dmitry commentedon Jun 30, 2025
In my environment it works as expected (pwsh 7.6.0.preview.4, Linux)
mklement0 commentedon Jun 30, 2025
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
$Errorafterwards; visualize withGet-Error).The parser error is
Incomplete string tokenand 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.237dmitry commentedon Jun 30, 2025
I thought TS especially marked where had to be tab. Otherwise, he probably would have mentioned additional conditions.
mklement0 commentedon Jun 30, 2025
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.
237dmitry commentedon Jun 30, 2025
Topic Starter
It works without new line after the last string (
`t) but not with`t`bnznrwn commentedon Jun 30, 2025