Skip to content

Commit 3fa6082

Browse files
Handle edge case where prompt is undefined (#1710)
1 parent 54d548e commit 3fa6082

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,18 @@ private void DoOneRepl(CancellationToken cancellationToken)
666666

667667
private string GetPrompt(CancellationToken cancellationToken)
668668
{
669-
var command = new PSCommand().AddCommand("prompt");
670-
IReadOnlyList<string> results = InvokePSCommand<string>(command, executionOptions: null, cancellationToken);
671-
string prompt = results.Count > 0 ? results[0] : DefaultPrompt;
669+
string prompt = DefaultPrompt;
670+
try
671+
{
672+
// TODO: Should we cache PSCommands like this as static members?
673+
var command = new PSCommand().AddCommand("prompt");
674+
IReadOnlyList<string> results = InvokePSCommand<string>(command, executionOptions: null, cancellationToken);
675+
if (results.Count > 0)
676+
{
677+
prompt = results[0];
678+
}
679+
}
680+
catch (CommandNotFoundException) { } // Use default prompt
672681

673682
if (CurrentRunspace.RunspaceOrigin != RunspaceOrigin.Local)
674683
{

0 commit comments

Comments
 (0)