Skip to content

Fix crash when seting PSSA rules w/Untitled active editor #606

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Security;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -247,11 +248,25 @@ private async Task HandleSetPSSARulesRequest(
}

var sendresult = requestContext.SendResult(null);
var scripFile = editorSession.Workspace.GetFile((string)dynParams.filepath);
ScriptFile scriptFile = null;
try
{
scriptFile = editorSession.Workspace.GetFile((string)dynParams.filepath);
}
catch (Exception ex) when (
ex is FileNotFoundException ||
ex is NotSupportedException ||
ex is PathTooLongException ||
ex is SecurityException)
{
var errMsg = $"Failed to get ScriptFile path for '{(string)dynParams.filepath}'";
Logger.WriteException(errMsg, ex);
}

await RunScriptDiagnostics(
new ScriptFile[] { scripFile },
editorSession,
this.messageSender.SendEvent);
(scriptFile != null) ? new ScriptFile[] { scriptFile } : new ScriptFile[0],
editorSession,
this.messageSender.SendEvent);
await sendresult;
}

Expand Down