From b64799f048d4b51699ed33bd2a11b4723f10f65f Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Thu, 31 Aug 2023 15:21:31 +0200 Subject: [PATCH 1/6] Diagnostics logger: remove exception rethrow during recovery --- src/Compiler/Facilities/DiagnosticsLogger.fs | 15 --------------- src/Compiler/Facilities/DiagnosticsLogger.fsi | 3 --- 2 files changed, 18 deletions(-) diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index a16c8bc083b..10aaeaa5158 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -411,20 +411,6 @@ module DiagnosticsLoggerExtensions = Debug.Assert(false, "Could not preserve stack trace for watson exception.") () - /// Reraise an exception if it is one we want to report to Watson. - let ReraiseIfWatsonable (exn: exn) = - match exn with - // These few SystemExceptions which we don't report to Watson are because we handle these in some way in Build.fs - | :? TargetInvocationException -> () - | :? NotSupportedException -> () - | :? System.IO.IOException -> () // This covers FileNotFoundException and DirectoryNotFoundException - | :? UnauthorizedAccessException -> () - | Failure _ // This gives reports for compiler INTERNAL ERRORs - | :? SystemException -> - PreserveStackTrace exn - raise exn - | _ -> () - type DiagnosticsLogger with member x.EmitDiagnostic(exn, severity) = @@ -473,7 +459,6 @@ module DiagnosticsLoggerExtensions = | _ -> try x.ErrorR(AttachRange m exn) // may raise exceptions, e.g. an fsi error sink raises StopProcessing. - ReraiseIfWatsonable exn with | ReportedError _ | WrappedError (ReportedError _, _) -> () diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fsi b/src/Compiler/Facilities/DiagnosticsLogger.fsi index 1f39261a668..6cfe7defb49 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fsi +++ b/src/Compiler/Facilities/DiagnosticsLogger.fsi @@ -242,9 +242,6 @@ module DiagnosticsLoggerExtensions = /// Instruct the exception not to reset itself when thrown again. val PreserveStackTrace: exn: 'T -> unit - /// Reraise an exception if it is one we want to report to Watson. - val ReraiseIfWatsonable: exn: exn -> unit - type DiagnosticsLogger with /// Report a diagnostic as an error and recover From 71d70c35c5374d827dc6345258dd05f2b57de2f1 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 1 Sep 2023 19:39:25 +0200 Subject: [PATCH 2/6] Report internal exceptions --- src/Compiler/Driver/CompilerDiagnostics.fs | 2 ++ src/Compiler/Facilities/DiagnosticsLogger.fs | 18 ++++++++++++++---- src/Compiler/Facilities/DiagnosticsLogger.fsi | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index 288d35222f3..b058c302b0c 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -131,6 +131,7 @@ type Exception with | DiagnosticEnabledWithLanguageFeature (_, _, m, _) | SyntaxError (_, m) | InternalError (_, m) + | InternalException (_, _, m) | InterfaceNotRevealed (_, _, m) | WrappedError (_, m) | PatternMatchCompilation.MatchIncomplete (_, _, m) @@ -1673,6 +1674,7 @@ type Exception with OutputNameSuggestions os suggestNames suggestionF idText | InternalError (s, _) + | InternalException(_, s, _) | InvalidArgument s | Failure s as exn -> ignore exn // use the argument, even in non DEBUG diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 10aaeaa5158..b2fed979a07 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -85,6 +85,17 @@ exception InternalError of message: string * range: range with | InternalError (msg, m) -> msg + m.ToString() | _ -> "impossible" +exception InternalException of exn: Exception * msg: string * range: range with + override this.Message = + match this :> exn with + | InternalException(_, msg, _) -> msg + | _ -> "impossible" + + override this.ToString() = + match this :> exn with + | InternalException(exn, _, _) -> exn.ToString() + | _ -> "impossible" + exception UserCompilerMessage of message: string * number: int * range: range exception LibraryUseOnly of range: range @@ -160,12 +171,10 @@ let rec AttachRange m (exn: exn) = else match exn with // Strip TargetInvocationException wrappers - | :? System.Reflection.TargetInvocationException -> AttachRange m exn.InnerException + | :? TargetInvocationException -> AttachRange m exn.InnerException | UnresolvedReferenceNoRange a -> UnresolvedReferenceError(a, m) | UnresolvedPathReferenceNoRange (a, p) -> UnresolvedPathReference(a, p, m) - | Failure msg -> InternalError(msg + " (Failure)", m) - | :? ArgumentException as exn -> InternalError(exn.Message + " (ArgumentException)", m) - | _ -> exn + | _ -> InternalException(exn, exn.Message, m) type Exiter = abstract Exit: int -> 'T @@ -416,6 +425,7 @@ module DiagnosticsLoggerExtensions = member x.EmitDiagnostic(exn, severity) = match exn with | InternalError (s, _) + | InternalException (_, s, _) | Failure s as exn -> Debug.Assert(false, sprintf "Unexpected exception raised in compiler: %s\n%s" s (exn.ToString())) | _ -> () diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fsi b/src/Compiler/Facilities/DiagnosticsLogger.fsi index 6cfe7defb49..e9040da36ed 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fsi +++ b/src/Compiler/Facilities/DiagnosticsLogger.fsi @@ -56,6 +56,8 @@ val Error: (int * string) * range -> exn exception InternalError of message: string * range: range +exception InternalException of exn: Exception * msg: string * range: range + exception UserCompilerMessage of message: string * number: int * range: range exception LibraryUseOnly of range: range From 9d99d2fa9e88dc000e92d0ae06f2ba567a9be036 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 1 Sep 2023 19:50:26 +0200 Subject: [PATCH 3/6] Fantomas --- src/Compiler/Driver/CompilerDiagnostics.fs | 2 +- src/Compiler/Facilities/DiagnosticsLogger.fs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index b058c302b0c..a8417dcf146 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -1674,7 +1674,7 @@ type Exception with OutputNameSuggestions os suggestNames suggestionF idText | InternalError (s, _) - | InternalException(_, s, _) + | InternalException (_, s, _) | InvalidArgument s | Failure s as exn -> ignore exn // use the argument, even in non DEBUG diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index b2fed979a07..6ab76510ff1 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -88,12 +88,12 @@ exception InternalError of message: string * range: range with exception InternalException of exn: Exception * msg: string * range: range with override this.Message = match this :> exn with - | InternalException(_, msg, _) -> msg + | InternalException (_, msg, _) -> msg | _ -> "impossible" override this.ToString() = match this :> exn with - | InternalException(exn, _, _) -> exn.ToString() + | InternalException (exn, _, _) -> exn.ToString() | _ -> "impossible" exception UserCompilerMessage of message: string * number: int * range: range From 6b93e61e56e539639640e5d80e9d5749c76b8aab Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 4 Sep 2023 12:20:52 +0200 Subject: [PATCH 4/6] Wrap system exceptions only --- src/Compiler/Facilities/DiagnosticsLogger.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 6ab76510ff1..0e95c3a8435 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -174,7 +174,8 @@ let rec AttachRange m (exn: exn) = | :? TargetInvocationException -> AttachRange m exn.InnerException | UnresolvedReferenceNoRange a -> UnresolvedReferenceError(a, m) | UnresolvedPathReferenceNoRange (a, p) -> UnresolvedPathReference(a, p, m) - | _ -> InternalException(exn, exn.Message, m) + | :? SystemException -> InternalException(exn, exn.Message, m) + | _ -> exn type Exiter = abstract Exit: int -> 'T From 017841c9e1b68c3894cac76a2701795ceb1ab508 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 4 Sep 2023 13:54:08 +0200 Subject: [PATCH 5/6] Exclude NotSupportedException --- src/Compiler/Facilities/DiagnosticsLogger.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 0e95c3a8435..941d6fecf17 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -174,6 +174,7 @@ let rec AttachRange m (exn: exn) = | :? TargetInvocationException -> AttachRange m exn.InnerException | UnresolvedReferenceNoRange a -> UnresolvedReferenceError(a, m) | UnresolvedPathReferenceNoRange (a, p) -> UnresolvedPathReference(a, p, m) + | :? NotSupportedException -> exn | :? SystemException -> InternalException(exn, exn.Message, m) | _ -> exn From aed5aa6cc5057cc06aff8bec04fad899828751cc Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 4 Sep 2023 14:02:04 +0200 Subject: [PATCH 6/6] Fantomas --- src/Compiler/Facilities/DiagnosticsLogger.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 941d6fecf17..b1edce3f820 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -174,7 +174,7 @@ let rec AttachRange m (exn: exn) = | :? TargetInvocationException -> AttachRange m exn.InnerException | UnresolvedReferenceNoRange a -> UnresolvedReferenceError(a, m) | UnresolvedPathReferenceNoRange (a, p) -> UnresolvedPathReference(a, p, m) - | :? NotSupportedException -> exn + | :? NotSupportedException -> exn | :? SystemException -> InternalException(exn, exn.Message, m) | _ -> exn