Skip to content

Commit 2be0669

Browse files
authored
Merge branch 'main' into ber.a/diagnosticData
2 parents 825d557 + f888031 commit 2be0669

30 files changed

+423
-226
lines changed

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type Exception with
132132
| DiagnosticEnabledWithLanguageFeature (_, _, m, _)
133133
| SyntaxError (_, m)
134134
| InternalError (_, m)
135+
| InternalException (_, _, m)
135136
| InterfaceNotRevealed (_, _, m)
136137
| WrappedError (_, m)
137138
| PatternMatchCompilation.MatchIncomplete (_, _, m)
@@ -1676,6 +1677,7 @@ type Exception with
16761677
OutputNameSuggestions os suggestNames suggestionF idText
16771678

16781679
| InternalError (s, _)
1680+
| InternalException (_, s, _)
16791681
| InvalidArgument s
16801682
| Failure s as exn ->
16811683
ignore exn // use the argument, even in non DEBUG

src/Compiler/Facilities/DiagnosticsLogger.fs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ exception InternalError of message: string * range: range with
8585
| InternalError (msg, m) -> msg + m.ToString()
8686
| _ -> "impossible"
8787

88+
exception InternalException of exn: Exception * msg: string * range: range with
89+
override this.Message =
90+
match this :> exn with
91+
| InternalException (_, msg, _) -> msg
92+
| _ -> "impossible"
93+
94+
override this.ToString() =
95+
match this :> exn with
96+
| InternalException (exn, _, _) -> exn.ToString()
97+
| _ -> "impossible"
98+
8899
exception UserCompilerMessage of message: string * number: int * range: range
89100

90101
exception LibraryUseOnly of range: range
@@ -160,11 +171,11 @@ let rec AttachRange m (exn: exn) =
160171
else
161172
match exn with
162173
// Strip TargetInvocationException wrappers
163-
| :? System.Reflection.TargetInvocationException -> AttachRange m exn.InnerException
174+
| :? TargetInvocationException -> AttachRange m exn.InnerException
164175
| UnresolvedReferenceNoRange a -> UnresolvedReferenceError(a, m)
165176
| UnresolvedPathReferenceNoRange (a, p) -> UnresolvedPathReference(a, p, m)
166-
| Failure msg -> InternalError(msg + " (Failure)", m)
167-
| :? ArgumentException as exn -> InternalError(exn.Message + " (ArgumentException)", m)
177+
| :? NotSupportedException -> exn
178+
| :? SystemException -> InternalException(exn, exn.Message, m)
168179
| _ -> exn
169180

170181
type Exiter =
@@ -411,25 +422,12 @@ module DiagnosticsLoggerExtensions =
411422
Debug.Assert(false, "Could not preserve stack trace for watson exception.")
412423
()
413424

414-
/// Reraise an exception if it is one we want to report to Watson.
415-
let ReraiseIfWatsonable (exn: exn) =
416-
match exn with
417-
// These few SystemExceptions which we don't report to Watson are because we handle these in some way in Build.fs
418-
| :? TargetInvocationException -> ()
419-
| :? NotSupportedException -> ()
420-
| :? System.IO.IOException -> () // This covers FileNotFoundException and DirectoryNotFoundException
421-
| :? UnauthorizedAccessException -> ()
422-
| Failure _ // This gives reports for compiler INTERNAL ERRORs
423-
| :? SystemException ->
424-
PreserveStackTrace exn
425-
raise exn
426-
| _ -> ()
427-
428425
type DiagnosticsLogger with
429426

430427
member x.EmitDiagnostic(exn, severity) =
431428
match exn with
432429
| InternalError (s, _)
430+
| InternalException (_, s, _)
433431
| Failure s as exn -> Debug.Assert(false, sprintf "Unexpected exception raised in compiler: %s\n%s" s (exn.ToString()))
434432
| _ -> ()
435433

@@ -473,7 +471,6 @@ module DiagnosticsLoggerExtensions =
473471
| _ ->
474472
try
475473
x.ErrorR(AttachRange m exn) // may raise exceptions, e.g. an fsi error sink raises StopProcessing.
476-
ReraiseIfWatsonable exn
477474
with
478475
| ReportedError _
479476
| WrappedError (ReportedError _, _) -> ()

src/Compiler/Facilities/DiagnosticsLogger.fsi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ val Error: (int * string) * range -> exn
5656

5757
exception InternalError of message: string * range: range
5858

59+
exception InternalException of exn: Exception * msg: string * range: range
60+
5961
exception UserCompilerMessage of message: string * number: int * range: range
6062

6163
exception LibraryUseOnly of range: range
@@ -242,9 +244,6 @@ module DiagnosticsLoggerExtensions =
242244
/// Instruct the exception not to reset itself when thrown again.
243245
val PreserveStackTrace: exn: 'T -> unit
244246

245-
/// Reraise an exception if it is one we want to report to Watson.
246-
val ReraiseIfWatsonable: exn: exn -> unit
247-
248247
type DiagnosticsLogger with
249248

250249
/// Report a diagnostic as an error and recover

0 commit comments

Comments
 (0)