-
Notifications
You must be signed in to change notification settings - Fork 234
VS Code Powershell Editor Services Throws Exception If Powershell Profile Contains ErrorActionPreference=Stop #1976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
At the end of the first pass, It looks like it sets the global to null $Global:__LastHistoryId = $LastHistoryEntry.Id # which is null pass 1:
pass 2:
pass 3
My annotations are the # Prevent installing more than once per session
if (Test-Path variable:global:__VSCodeOriginalPrompt) {
return;
}
# Disable shell integration when the language mode is restricted
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
return;
}
$Global:__VSCodeOriginalPrompt = $function:Prompt
$Global:__LastHistoryId = -1
function Global:Prompt() {
$FakeCode = [int]!$global:?
$LastHistoryEntry = Get-History -Count 1
# 🦓 $LastHistoryEntry: is true null
# Skip finishing the command if the first command has not yet started
if ($Global:__LastHistoryId -ne -1) {
# 🦓 -1 -ne -1 == false
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
# if entered 🦓 $null.Id -eq -1 == false
}
else {
# if entered then 🦓 that means: $Global:__LastHistoryId != -1
$Result = '..'
if ($LastHistoryEntry.CommandLine) {
#🦓 if $null , therefore: false
$CommandLine = $LastHistoryEntry.CommandLine
}
else {
$CommandLine = ""
}
}
}
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
$Global:__LastHistoryId = $LastHistoryEntry.Id
# 🦓 $global:__lastHistoryId = $null
return $Result
} |
Thank you @ninmonkey , I'm not much familiar with this process but I understand that you were able to repro this issue. Should I propose a code-based solution & open a pull-request myself or will someone from the dev-team do this within a time-frame upon availability? |
This should be resolved. The problem was actually the use of
to the prompt wrapper in that script. |
This issue has been marked as answered and has not had any activity in a day. It has been automatically closed for housekeeping purposes. |
Prerequisites
Steps to reproduce
Hello,
With the latest update of VS Code (v1.74.1) Powershell Extension (v2022.12.1), with Terminal > Integrated > Shell Integration: Enabled (Checked), Powershell Editor Services throws exception at startup if the powershell profile script file (Microsoft.VSCode_profile.ps1) contains
It fails in file "src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs", at line 567 (function Global:Prompt()):
because $LastHistoryEntry is null. Looking at the code fragment, I understand that at line 529 the assignment statement might result in $null value (or the resulting object might not contain Id property) which is not handled properly.
Expected behavior
Setting
$ErrorActionPreference = "Stop"; Set-StrictMode -Version Latest
in powershell profile script should not cause any startup errors inside Powershell Editor Services.
Actual behavior
At editor services startup (with Powershell profile loaded in terminal):
Error details
Environment data
Version
Powershell Extension Version: v2022.12.1, VSCode Version: 1.74.1
Visuals
No response
The text was updated successfully, but these errors were encountered: