diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index 288d35222f3..a8417dcf146 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 a16c8bc083b..b1edce3f820 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,11 +171,11 @@ 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) + | :? NotSupportedException -> exn + | :? SystemException -> InternalException(exn, exn.Message, m) | _ -> exn type Exiter = @@ -411,25 +422,12 @@ 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) = 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())) | _ -> () @@ -473,7 +471,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..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 @@ -242,9 +244,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