Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type Exception with
| DiagnosticEnabledWithLanguageFeature (_, _, m, _)
| SyntaxError (_, m)
| InternalError (_, m)
| InternalException (_, _, m)
| InterfaceNotRevealed (_, _, m)
| WrappedError (_, m)
| PatternMatchCompilation.MatchIncomplete (_, _, m)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 15 additions & 18 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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()))
| _ -> ()

Expand Down Expand Up @@ -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 _, _) -> ()
Expand Down
5 changes: 2 additions & 3 deletions src/Compiler/Facilities/DiagnosticsLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down