@@ -65,24 +65,38 @@ param(
65
65
$ConfirmInstall
66
66
)
67
67
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 ;
70
77
}
71
78
72
79
# Are we running in PowerShell 2 or earlier?
73
80
if ($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
79
84
80
- # Notify the client that the services have started
81
- WriteSessionFile $resultDetails
85
+ ExitWithError " Unsupported PowerShell version $ ( $PSVersionTable .PSVersion ) , language features are disabled. "
86
+ }
82
87
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
+ }
84
98
85
- exit 0 ;
99
+ ExitWithError " PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled. "
86
100
}
87
101
88
102
# Are we running in PowerShell 5 or later?
@@ -240,5 +254,5 @@ catch [System.Exception] {
240
254
$e = $e.InnerException ;
241
255
}
242
256
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 )
244
258
}
0 commit comments