Skip to content

Commit 0ac14d9

Browse files
committed
Fix PSES crash that happens if you format an empty PS doc
Invoke-Formatter -ScriptDefinition '' - throws a terminating error: ParameterBinderValidationException. I suppose we could have added another catch statement to the InvokePowerShell method in the AnalysisService but in general, we probably want to know about such bugs. Also, we could also update the extension to not send a format request for an empty doc but I'm not sure it's worth the additional code change given corner case scenario. But I could be convinced otherwise.
1 parent cfea694 commit 0ac14d9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ public async Task<string> Format(
263263
Hashtable settings,
264264
int[] rangeList)
265265
{
266-
// we cannot use Range type therefore this workaround of using -1 default value
267-
if (!_hasScriptAnalyzerModule)
266+
// We cannot use Range type therefore this workaround of using -1 default value.
267+
// Invoke-Formatter throws a ParameterBinderValidationException if the ScriptDefinition is an empty string.
268+
if (!_hasScriptAnalyzerModule || string.IsNullOrEmpty(scriptDefinition))
268269
{
269270
return null;
270271
}

0 commit comments

Comments
 (0)