Skip to content

Commit c39e298

Browse files
committed
Change WriteErrorsToHost to ThrowOnError
1 parent c9b782f commit c39e298

File tree

10 files changed

+14
-13
lines changed

10 files changed

+14
-13
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal class ConfigurationDoneHandler : IConfigurationDoneHandler
2828
MustRunInForeground = true,
2929
WriteInputToHost = true,
3030
WriteOutputToHost = true,
31+
ThrowOnError = false,
3132
AddToHistory = true,
3233
};
3334

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request,
5050
_executionService.ExecutePSCommandAsync(
5151
new PSCommand().AddScript(request.Expression),
5252
CancellationToken.None,
53-
new PowerShellExecutionOptions { WriteOutputToHost = true }).HandleErrorsAsync(_logger);
53+
new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger);
5454
}
5555
else
5656
{

src/PowerShellEditorServices/Services/Extension/ExtensionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public async Task InvokeCommandAsync(string commandName, EditorContext editorCon
135135
await ExecutionService.ExecutePSCommandAsync(
136136
executeCommand,
137137
CancellationToken.None,
138-
new PowerShellExecutionOptions { WriteOutputToHost = !editorCommand.SuppressOutput })
138+
new PowerShellExecutionOptions { WriteOutputToHost = !editorCommand.SuppressOutput, ThrowOnError = false, AddToHistory = !editorCommand.SuppressOutput })
139139
.ConfigureAwait(false);
140140
}
141141
else

src/PowerShellEditorServices/Services/PowerShell/Execution/ExecutionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public record PowerShellExecutionOptions : ExecutionOptions
3939
InterruptCurrentForeground = false,
4040
WriteOutputToHost = false,
4141
WriteInputToHost = false,
42-
WriteErrorsToHost = false,
42+
ThrowOnError = true,
4343
AddToHistory = false,
4444
};
4545

4646
public bool WriteOutputToHost { get; init; }
4747

4848
public bool WriteInputToHost { get; init; }
4949

50-
public bool WriteErrorsToHost { get; init; }
50+
public bool ThrowOnError { get; init; }
5151

5252
public bool AddToHistory { get; init; }
5353
}

src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private IReadOnlyList<TResult> ExecuteNormally(CancellationToken cancellationTok
7575
AddToHistory = PowerShellExecutionOptions.AddToHistory,
7676
};
7777

78-
if (!PowerShellExecutionOptions.WriteErrorsToHost)
78+
if (PowerShellExecutionOptions.ThrowOnError)
7979
{
8080
invocationSettings.ErrorActionPreference = ActionPreference.Stop;
8181
}
@@ -94,7 +94,7 @@ private IReadOnlyList<TResult> ExecuteNormally(CancellationToken cancellationTok
9494
{
9595
Logger.LogWarning($"Runtime exception occurred while executing command:{Environment.NewLine}{Environment.NewLine}{e}");
9696

97-
if (!PowerShellExecutionOptions.WriteErrorsToHost)
97+
if (PowerShellExecutionOptions.ThrowOnError)
9898
{
9999
throw;
100100
}
@@ -161,7 +161,7 @@ private IReadOnlyList<TResult> ExecuteInDebugger(CancellationToken cancellationT
161161
{
162162
Logger.LogWarning($"Runtime exception occurred while executing command:{Environment.NewLine}{Environment.NewLine}{e}");
163163

164-
if (!PowerShellExecutionOptions.WriteErrorsToHost)
164+
if (!PowerShellExecutionOptions.ThrowOnError)
165165
{
166166
throw;
167167
}

src/PowerShellEditorServices/Services/PowerShell/Handlers/EvaluateHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request, Cance
3535
_executionService.ExecutePSCommandAsync(
3636
new PSCommand().AddScript(request.Expression),
3737
CancellationToken.None,
38-
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true });
38+
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false });
3939

4040
return Task.FromResult(new EvaluateResponseBody
4141
{

src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private async Task CheckPackageManagement()
127127
await _executionService.ExecutePSCommandAsync(
128128
command,
129129
CancellationToken.None,
130-
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true }).ConfigureAwait(false);
130+
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false }).ConfigureAwait(false);
131131

132132
// TODO: Error handling here
133133

src/PowerShellEditorServices/Services/PowerShell/Handlers/ShowHelpHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public async Task<Unit> Handle(ShowHelpParams request, CancellationToken cancell
7474

7575
// TODO: Rather than print the help in the console, we should send the string back
7676
// to VSCode to display in a help pop-up (or similar)
77-
await _executionService.ExecutePSCommandAsync<PSObject>(checkHelpPSCommand, cancellationToken, new PowerShellExecutionOptions { WriteOutputToHost = true }).ConfigureAwait(false);
77+
await _executionService.ExecutePSCommandAsync<PSObject>(checkHelpPSCommand, cancellationToken, new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false }).ConfigureAwait(false);
7878
return Unit.Value;
7979
}
8080
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public async Task StartAsync(HostStartOptions startOptions, CancellationToken ca
179179
{
180180
await ExecuteDelegateAsync(
181181
"LoadProfiles",
182-
new PowerShellExecutionOptions { MustRunInForeground = true },
182+
new PowerShellExecutionOptions { MustRunInForeground = true, ThrowOnError = false },
183183
(pwsh, delegateCancellation) => pwsh.LoadProfiles(_hostInfo.ProfilePaths),
184184
cancellationToken).ConfigureAwait(false);
185185

@@ -549,7 +549,7 @@ private string InvokeReadLine(CancellationToken cancellationToken)
549549
private void InvokeInput(string input, CancellationToken cancellationToken)
550550
{
551551
var command = new PSCommand().AddScript(input, useLocalScope: false);
552-
InvokePSCommand(command, new PowerShellExecutionOptions { AddToHistory = true, WriteErrorsToHost = true, WriteOutputToHost = true }, cancellationToken);
552+
InvokePSCommand(command, new PowerShellExecutionOptions { AddToHistory = true, ThrowOnError = false, WriteOutputToHost = true }, cancellationToken);
553553
}
554554

555555
private void AddRunspaceEventHandlers(Runspace runspace)

src/PowerShellEditorServices/Services/Template/TemplateService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public async Task<bool> CreateFromTemplateAsync(
166166
await _executionService.ExecutePSCommandAsync(
167167
command,
168168
CancellationToken.None,
169-
new PowerShellExecutionOptions { WriteOutputToHost = true, InterruptCurrentForeground = true }).ConfigureAwait(false);
169+
new PowerShellExecutionOptions { WriteOutputToHost = true, InterruptCurrentForeground = true, ThrowOnError = false }).ConfigureAwait(false);
170170

171171
// If any errors were written out, creation was not successful
172172
return true;

0 commit comments

Comments
 (0)