Skip to content

Commit c43c84f

Browse files
committed
Fix #181: Fix crash for unsupported field types
This change adds proper error handling for input prompt requests for field types that we don't yet support like SecureString and PSCredential. Previously any Read-Host or Get-Credential call which prompts for either of these types would crash the language and debugging services. The fix causes errors to be written to the host stating that these commands and field types are not yet supported.
1 parent cff81f8 commit c43c84f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/PowerShellEditorServices/Console/FieldDetails.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.Management.Automation;
1111
using System.Management.Automation.Host;
12+
using System.Security;
1213

1314
namespace Microsoft.PowerShell.EditorServices.Console
1415
{
@@ -89,7 +90,17 @@ public FieldDetails(
8990
this.IsMandatory = isMandatory;
9091
this.DefaultValue = defaultValue;
9192

92-
if (typeof(IList).IsAssignableFrom(fieldType))
93+
if (typeof(SecureString) == fieldType)
94+
{
95+
throw new NotSupportedException(
96+
"Input fields of type 'SecureString' are currently not supported.");
97+
}
98+
else if (typeof(PSCredential) == fieldType)
99+
{
100+
throw new NotSupportedException(
101+
"Input fields of type 'PSCredential' are currently not supported.");
102+
}
103+
else if (typeof(IList).IsAssignableFrom(fieldType))
93104
{
94105
this.IsCollection = true;
95106
this.ElementType = typeof(object);

src/PowerShellEditorServices/Session/SessionPSHostUserInterface.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public override PSCredential PromptForCredential(
154154
PSCredentialTypes allowedCredentialTypes,
155155
PSCredentialUIOptions options)
156156
{
157-
throw new NotImplementedException();
157+
throw new NotSupportedException(
158+
"'Get-Credential' is not yet supported.");
158159
}
159160

160161
public override PSCredential PromptForCredential(
@@ -163,7 +164,13 @@ public override PSCredential PromptForCredential(
163164
string userName,
164165
string targetName)
165166
{
166-
throw new NotImplementedException();
167+
return this.PromptForCredential(
168+
caption,
169+
message,
170+
userName,
171+
targetName,
172+
PSCredentialTypes.Default,
173+
PSCredentialUIOptions.Default);
167174
}
168175

169176
public override PSHostRawUserInterface RawUI
@@ -198,7 +205,8 @@ public override string ReadLine()
198205

199206
public override SecureString ReadLineAsSecureString()
200207
{
201-
throw new NotImplementedException();
208+
throw new NotSupportedException(
209+
"'Read-Host -AsSecureString' is not yet supported.");
202210
}
203211

204212
public override void Write(

0 commit comments

Comments
 (0)