Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void VisitNamespaceMembersAsTasks(NamespaceSymbol symbol)
{
Visit(m);
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorSeverity.General should be the default. This coding pattern is unnecessarily burdensome.

{
throw ExceptionUtilities.Unreachable;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private Task CompileNamespaceAsAsync(NamespaceSymbol symbol)
{
CompileNamespace(symbol);
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.Critical))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -418,7 +418,7 @@ private Task CompileNamedTypeAsync(NamedTypeSymbol symbol)
{
CompileNamedType(symbol);
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.Critical))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override TypeSymbol LookupTopLevelTypeDefSymbol(
{
return assembly.LookupTopLevelMetadataType(ref emittedName, digThroughForwardedTypes: true);
}
catch (Exception e) when (FatalError.ReportAndPropagate(e)) // Trying to get more useful Watson dumps.
catch (Exception e) when (FatalError.ReportAndPropagate(e, ErrorSeverity.General)) // Trying to get more useful Watson dumps.
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task OnCompilationEventsGeneratedAsync(
OnCompilationEventsGenerated_NoLock(getCompilationEvents(eventQueue, additionalFiles));
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ private async Task ProcessCompilationEventsAsync(AnalysisScope analysisScope, An
await ProcessEventAsync(completedEvent, analysisScope, analysisState, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -1468,7 +1468,7 @@ private async Task ProcessCompilationEventsAsync(AnalysisScope analysisScope, An

return completedEvent;
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ private async Task ComputeAnalyzerSyntaxDiagnosticsAsync(AnalysisScope analysisS
await ComputeAnalyzerDiagnosticsAsync(pendingAnalysisScope, getPendingEventsOpt: null, taskToken, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -701,7 +701,7 @@ private async Task ComputeAnalyzerSemanticDiagnosticsAsync(SemanticModel model,
}
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -832,7 +832,7 @@ await Task.WhenAll(partialTrees.Select(tree =>
FreeEventQueue(eventQueue, _eventQueuePool);
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ await Task.WhenAll(partialTrees.Select(tree =>
FreeDriver(driver);
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -991,7 +991,7 @@ private async Task<AnalyzerDriver> GetAnalyzerDriverAsync(CancellationToken canc
}
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -1038,7 +1038,7 @@ private async Task ComputeAnalyzerDiagnosticsCoreAsync(AnalyzerDriver driver, As
}
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -1168,7 +1168,7 @@ private async Task<Task> SetActiveTreeAnalysisTaskAsync(Func<Tuple<Task, Cancell
await WaitForExecutingTaskAsync(executingTreeTask.Item1, alwaysYield: true).ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down Expand Up @@ -1386,7 +1386,7 @@ public async Task<AnalyzerTelemetryInfo> GetAnalyzerTelemetryInfoAsync(Diagnosti
var executionTime = GetAnalyzerExecutionTime(analyzer);
return new AnalyzerTelemetryInfo(actionCounts, suppressionActionCounts, executionTime);
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
21 changes: 8 additions & 13 deletions src/Compilers/Core/Portable/InternalUtilities/FatalError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void CopyHandlerTo(Assembly assembly)
/// </summary>
/// <returns><see langword="false"/> to avoid catching the exception.</returns>
[DebuggerHidden]
public static bool ReportAndPropagate(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndPropagate(Exception exception, ErrorSeverity severity)
{
Report(exception, severity);
return false;
Expand All @@ -105,7 +105,7 @@ public static bool ReportAndPropagate(Exception exception, ErrorSeverity severit
/// </summary>
/// <returns><see langword="false"/> to avoid catching the exception.</returns>
[DebuggerHidden]
public static bool ReportAndPropagateUnlessCanceled(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndPropagateUnlessCanceled(Exception exception, ErrorSeverity severity)
{
if (exception is OperationCanceledException)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public static bool ReportAndPropagateUnlessCanceled(Exception exception, ErrorSe
/// <see cref="CancellationToken.IsCancellationRequested"/> set if cancellation is expected.</param>
/// <returns><see langword="false"/> to avoid catching the exception.</returns>
[DebuggerHidden]
public static bool ReportAndPropagateUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndPropagateUnlessCanceled(Exception exception, ErrorSeverity severity, CancellationToken contextCancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did 'Change Signature' make this easy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did! Although sometimes it did nothing at all, and my effort to debug that kept resulting in the debugger breaking. 😄

{
if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken))
{
Expand All @@ -160,14 +160,14 @@ public static bool ReportAndPropagateUnlessCanceled(Exception exception, Cancell
/// </summary>
/// <returns>True to catch the exception.</returns>
[DebuggerHidden]
public static bool ReportAndCatch(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndCatch(Exception exception, ErrorSeverity severity)
{
Report(exception, severity);
return true;
}

[DebuggerHidden]
public static bool ReportWithDumpAndCatch(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportWithDumpAndCatch(Exception exception, ErrorSeverity severity)
{
Report(exception, severity, forceDump: true);
return true;
Expand All @@ -180,7 +180,7 @@ public static bool ReportWithDumpAndCatch(Exception exception, ErrorSeverity sev
/// <returns><see langword="true"/> to catch the exception if the error was reported; otherwise,
/// <see langword="false"/> to propagate the exception if the operation was cancelled.</returns>
[DebuggerHidden]
public static bool ReportAndCatchUnlessCanceled(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndCatchUnlessCanceled(Exception exception, ErrorSeverity severity)
{
if (exception is OperationCanceledException)
{
Expand Down Expand Up @@ -210,7 +210,7 @@ public static bool ReportAndCatchUnlessCanceled(Exception exception, ErrorSeveri
/// <returns><see langword="true"/> to catch the exception if the error was reported; otherwise,
/// <see langword="false"/> to propagate the exception if the operation was cancelled.</returns>
[DebuggerHidden]
public static bool ReportAndCatchUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
public static bool ReportAndCatchUnlessCanceled(Exception exception, ErrorSeverity severity, CancellationToken contextCancellationToken)
{
if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken))
{
Expand All @@ -224,7 +224,7 @@ public static bool ReportAndCatchUnlessCanceled(Exception exception, Cancellatio

private static readonly object s_reportedMarker = new();

private static void Report(Exception exception, ErrorSeverity severity = ErrorSeverity.Uncategorized, bool forceDump = false)
private static void Report(Exception exception, ErrorSeverity severity, bool forceDump = false)
{
// hold onto last exception to make investigation easier
s_reportedException = exception;
Expand Down Expand Up @@ -264,11 +264,6 @@ private static void Report(Exception exception, ErrorSeverity severity = ErrorSe
/// </summary>
internal enum ErrorSeverity
{
/// <summary>
/// The severity hasn't been categorized. Don't use this in new code.
/// </summary>
Uncategorized,

/// <summary>
/// Something failed, but the user is unlikely to notice. Especially useful for background things that we can silently recover
/// from, like bugs in caching systems.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void errorHandlingBody(int i)
{
body(i);
}
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General, cancellationToken))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Sub()
Try
VisitModule(m)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General)
Throw ExceptionUtilities.Unreachable
End Try
End Sub),
Expand Down Expand Up @@ -156,7 +156,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Sub()
Try
Visit(m)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General)
Throw ExceptionUtilities.Unreachable
End Try
End Sub),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Sub()
Try
CompileNamespace(symbol)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.Critical)
Throw ExceptionUtilities.Unreachable
End Try
End Sub),
Expand Down Expand Up @@ -534,7 +534,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Sub()
Try
CompileNamedType(symbol, filter)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.Critical)
Throw ExceptionUtilities.Unreachable
End Try
End Sub),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE

Try
Return assembly.LookupTopLevelMetadataType(emittedName, digThroughForwardedTypes:=True)
Catch e As Exception When FatalError.ReportAndPropagate(e) ' Trying to get more useful Watson dumps.
Catch e As Exception When FatalError.ReportAndPropagate(e, ErrorSeverity.General) ' Trying to get more useful Watson dumps.
Throw ExceptionUtilities.Unreachable
End Try
End Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Sub()
Try
visitor(symbol)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e)
Catch e As Exception When FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.Critical)
Throw ExceptionUtilities.Unreachable
End Try
End Sub),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private async Task StreamingFindBaseSymbolsAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private async Task FindDerivedSymbolsAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async Task FindExtensionMethodsAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async Task FindImplementingMembersAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private async Task FindMemberOverloadsAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async Task StreamingFindReferencesAsync(
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Critical))
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public async Task<ExecutionResult> ExecuteCodeAsync(string text)
var isSuccessful = await _session.ExecuteCodeAsync(text).ConfigureAwait(false);
return new ExecutionResult(isSuccessful);
}
catch (Exception e) when (FatalError.ReportAndPropagate(e))
catch (Exception e) when (FatalError.ReportAndPropagate(e, ErrorSeverity.General))
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ await _presenter.TryNavigateToOrPresentItemsAsync(
catch (OperationCanceledException)
{
}
catch (Exception ex) when (FatalError.ReportAndCatch(ex))
catch (Exception ex) when (FatalError.ReportAndCatch(ex, ErrorSeverity.Critical))
{
}
}
Expand Down
Loading