Skip to content

Commit 60e37b4

Browse files
Write exception messages when watch fails
Instead of a blank watch message we now write the exception message that was thrown from the attempt.
1 parent d490e7a commit 60e37b4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,22 @@ public async Task<VariableDetails> EvaluateExpressionAsync(
497497
bool writeResultAsOutput)
498498
{
499499
PSCommand command = new PSCommand().AddScript(expressionString);
500-
IReadOnlyList<PSObject> results = await _executionService.ExecutePSCommandAsync<PSObject>(
501-
command,
502-
CancellationToken.None,
503-
new PowerShellExecutionOptions { WriteOutputToHost = writeResultAsOutput, ThrowOnError = !writeResultAsOutput }).ConfigureAwait(false);
500+
IReadOnlyList<PSObject> results;
501+
try
502+
{
503+
results = await _executionService.ExecutePSCommandAsync<PSObject>(
504+
command,
505+
CancellationToken.None,
506+
new PowerShellExecutionOptions { WriteOutputToHost = writeResultAsOutput, ThrowOnError = !writeResultAsOutput }).ConfigureAwait(false);
507+
}
508+
catch (Exception e)
509+
{
510+
// If a watch expression throws we want to show the exception.
511+
// TODO: Show the exception as an expandable object.
512+
return new VariableDetails(
513+
expressionString,
514+
$"{e.GetType().Name}: {e.Message}");
515+
}
504516

505517
// Since this method should only be getting invoked in the debugger,
506518
// we can assume that Out-String will be getting used to format results

0 commit comments

Comments
 (0)