Skip to content

Commit

Permalink
Merge pull request #54573 from ryzngard/issues/54149_codeaction_error…
Browse files Browse the repository at this point in the history
…_reporting

Add ErrorReporting for CodeAction Apply
  • Loading branch information
ryzngard committed Jul 6, 2021
2 parents f32db1d + 0b01208 commit e7764ce
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Undo;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Notification;
Expand Down Expand Up @@ -134,7 +135,7 @@ public bool Apply(

var oldSolution = workspace.CurrentSolution;

bool applied;
var applied = false;

// Determine if we're making a simple text edit to a single file or not.
// If we're not, then we need to make a linked global undo to wrap the
Expand All @@ -152,7 +153,14 @@ public bool Apply(

using (workspace.Services.GetService<ISourceTextUndoService>().RegisterUndoTransaction(text, title))
{
applied = operations.Single().TryApply(workspace, progressTracker, cancellationToken);
try
{
applied = operations.Single().TryApply(workspace, progressTracker, cancellationToken);
}
catch (Exception ex) when (FatalError.ReportAndPropagateUnlessCanceled(ex, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
}
}
else
Expand All @@ -169,9 +177,16 @@ public bool Apply(
transaction.AddDocument(fromDocument.Id);
}

applied = ProcessOperations(
workspace, operations, progressTracker,
cancellationToken);
try
{
applied = ProcessOperations(
workspace, operations, progressTracker,
cancellationToken);
}
catch (Exception ex) when (FatalError.ReportAndPropagateUnlessCanceled(ex, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}

transaction.Commit();
}
Expand Down

0 comments on commit e7764ce

Please sign in to comment.