Skip to content

Commit dfcbf0e

Browse files
Handle incomingSettings and profileObject being null (#1504)
* Added null check for incomingSettings.Powershell to prevent SendFeatureChangesTelemetry from throwing an exception when accessing Powershell and its properties. * Added null check in GetProfilePathFromProfileObject to prevent NullReferenceException if profileObject is null. Co-authored-by: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
1 parent da481f2 commit dfcbf0e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ private EditorServicesConfig CreateConfigObject()
378378
private string GetProfilePathFromProfileObject(PSObject profileObject, ProfileUserKind userKind, ProfileHostKind hostKind)
379379
{
380380
string profilePathName = $"{userKind}{hostKind}";
381-
381+
if (profileObject is null)
382+
{
383+
return null;
384+
}
382385
string pwshProfilePath = (string)profileObject.Properties[profilePathName].Value;
383386

384387
if (hostKind == ProfileHostKind.AllHosts)

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
5151
{
5252
LanguageServerSettingsWrapper incomingSettings = request.Settings.ToObject<LanguageServerSettingsWrapper>();
5353
this._logger.LogTrace("Handling DidChangeConfiguration");
54-
if (incomingSettings == null)
54+
if (incomingSettings is null || incomingSettings.Powershell is null)
5555
{
5656
this._logger.LogTrace("Incoming settings were null");
5757
return await Unit.Task.ConfigureAwait(false);

0 commit comments

Comments
 (0)