@@ -65,24 +65,38 @@ param(
6565 $ConfirmInstall
6666)
6767
68- function WriteSessionFile ($sessionInfo ) {
69- ConvertTo-Json - InputObject $sessionInfo - Compress | Set-Content - Force - Path " $SessionDetailsPath " - ErrorAction Stop
68+ function ExitWithError ($errorString ) {
69+
70+ Write-Host - ForegroundColor Red " `n`n $errorString "
71+
72+ # Sleep for a while to make sure the user has time to see and copy the
73+ # error message
74+ Start-Sleep - Seconds 300
75+
76+ exit 1 ;
7077}
7178
7279# Are we running in PowerShell 2 or earlier?
7380if ($PSVersionTable.PSVersion.Major -le 2 ) {
74- $resultDetails = @ {
75- " status" = " failed"
76- " reason" = " unsupported"
77- " powerShellVersion" = $PSVersionTable.PSVersion.ToString ()
78- };
81+ # No ConvertTo-Json on PSv2 and below, so write out the JSON manually
82+ " {`" status`" : `" failed`" , `" reason`" : `" unsupported`" , `" powerShellVersion`" : `" $ ( $PSVersionTable.PSVersion.ToString ()) `" }" |
83+ Set-Content - Force - Path " $SessionDetailsPath " - ErrorAction Stop
7984
80- # Notify the client that the services have started
81- WriteSessionFile $resultDetails
85+ ExitWithError " Unsupported PowerShell version $ ( $PSVersionTable .PSVersion ) , language features are disabled. "
86+ }
8287
83- Write-Host " Unsupported PowerShell version $ ( $PSVersionTable.PSVersion ) , language features are disabled.`n "
88+ function WriteSessionFile ($sessionInfo ) {
89+ ConvertTo-Json - InputObject $sessionInfo - Compress | Set-Content - Force - Path " $SessionDetailsPath " - ErrorAction Stop
90+ }
91+
92+ if ($host.Runspace.LanguageMode -eq ' ConstrainedLanguage' ) {
93+ WriteSessionFile @ {
94+ " status" = " failed"
95+ " reason" = " languageMode"
96+ " detail" = $host.Runspace.LanguageMode.ToString ()
97+ }
8498
85- exit 0 ;
99+ ExitWithError " PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled. "
86100}
87101
88102# Are we running in PowerShell 5 or later?
@@ -240,5 +254,5 @@ catch [System.Exception] {
240254 $e = $e.InnerException ;
241255 }
242256
243- Write-Error (" `r`n Caught error while waiting for EditorServicesHost to complete:`r`n " + $errorString )
257+ ExitWithError (" Caught error while waiting for EditorServicesHost to complete:`r`n " + $errorString )
244258}
0 commit comments