Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3d0607

Browse files
dsymebrettfo
authored andcommitted
improve stack traces for watson exns (#3385)
* improve stack traces for watson exns* improve stack traces for watson exns* improve stack traces for watson exns* improve stack traces for watson exns
1 parent18abbaf commite3d0607

File tree

4 files changed

+64
-31
lines changed

4 files changed

+64
-31
lines changed

‎src/fsharp/ErrorLogger.fs‎

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ open System
2222
/// Represents the style being used to format errors
2323
[<RequireQualifiedAccess>]
2424
typeErrorStyle=
25-
| DefaultErrors
26-
| EmacsErrors
27-
| TestErrors
28-
| VSErrors
29-
| GccErrors
25+
| DefaultErrors
26+
| EmacsErrors
27+
| TestErrors
28+
| VSErrors
29+
| GccErrors
3030

3131
/// Thrown when we want to add some range information to a .NET exception
32-
exception WrappedErrorofexn*range
32+
exception WrappedErrorofexn*rangewith
33+
overridethis.Message=
34+
match this:> exnwith
35+
| WrappedError(exn,_)->"WrappedError("+ exn.Message+")"
36+
|_->"WrappedError"
3337

3438
/// Thrown when immediate, local error recovery is not possible. This indicates
3539
/// we've reported an error but need to make a non-local transfer of control.
@@ -39,28 +43,35 @@ exception WrappedError of exn * range
3943
/// situations (LazyWithContext) we may need to re-report the original error
4044
/// when a lazy thunk is re-evaluated.
4145
exception ReportedErrorofexnoptionwith
42-
overridethis.Message=
46+
overridethis.Message=
47+
letmsg="The exception has been reported. This internal exception should now be caught at an error recovery point on the stack."
4348
match this:> exnwith
44-
| ReportedError(Some exn)-> exn.Message
45-
|_->"ReportedError"
49+
| ReportedError(Some exn)->msg+" Original message:"+exn.Message+")"
50+
|_->msg
4651

4752
let recfindOriginalException err=
4853
match errwith
4954
| ReportedError(Some err)-> err
5055
| WrappedError(err,_)-> findOriginalException err
5156
|_-> err
5257

53-
5458
typeSuggestions= unit-> Set<string>
5559

5660
letNoSuggestions:Suggestions=fun()-> Set.empty
5761

5862
/// Thrown when we stop processing the F# Interactive entry or #load.
59-
exception StopProcessingExnofexnoption
63+
exception StopProcessingExnofexnoptionwith
64+
overridethis.Message="Processing of a script fragment has stopped because an exception has been raised"
65+
66+
overridethis.ToString()=
67+
match this:> exnwith
68+
| StopProcessingExn(Some exn)->"StopProcessingExn, originally ("+ exn.ToString()+")"
69+
|_->"StopProcessingExn"
70+
71+
6072
let(|StopProcessing|_|)exn=match exnwith StopProcessingExn_-> Some()|_-> None
6173
letStopProcessing<'T>= StopProcessingExn None
6274

63-
(* common error kinds*)
6475
exception NumberedErrorof(int*string)*rangewith// int is e.g. 191 in FS0191
6576
overridethis.Message=
6677
match this:> exnwith
@@ -74,26 +85,32 @@ exception Error of (int * string) * range with // int is e.g. 191 in FS0191 /
7485
|_->"impossible"
7586

7687

77-
exceptionErrorWithSuggestionsof(int*string)*range*string*Suggestionswith// int is e.g. 191 in FS0191
78-
overridethis.Message=
79-
match this:> exnwith
80-
|ErrorWithSuggestions((_,msg),_,_,_)-> msg
88+
exceptionInternalErrorofmsg:string*rangewith
89+
overridethis.Message=
90+
match this:> exnwith
91+
|InternalError(msg,m)-> msg+ m.ToString()
8192
|_->"impossible"
8293

83-
exception InternalErrorofstring*range
8494
exception UserCompilerMessageofstring*int*range
8595
exception LibraryUseOnlyofrange
8696
exception Deprecatedofstring*range
8797
exception Experimentalofstring*range
8898
exception PossibleUnverifiableCodeofrange
8999

90-
// Range/NoRange Duals
91100
exception UnresolvedReferenceNoRangeof(*assemblyname*)string
92101
exception UnresolvedReferenceErrorof(*assemblyname*)string*range
93102
exception UnresolvedPathReferenceNoRangeof(*assemblyname*)string*(*path*)string
94103
exception UnresolvedPathReferenceof(*assemblyname*)string*(*path*)string*range
95104

96105

106+
107+
exception ErrorWithSuggestionsof(int*string)*range*string*Suggestionswith// int is e.g. 191 in FS0191
108+
overridethis.Message=
109+
match this:> exnwith
110+
| ErrorWithSuggestions((_,msg),_,_,_)-> msg
111+
|_->"impossible"
112+
113+
97114
let inlineprotectAssemblyExploration dflt f=
98115
try
99116
f()
@@ -149,9 +166,9 @@ let QuitProcessExiter =
149166
typeBuildPhase=
150167
| DefaultPhase
151168
| Compile
152-
|Parameter| Parse| TypeCheck
169+
| Parameter| Parse| TypeCheck
153170
| CodeGen
154-
|Optimize| IlxGen| IlGen| Output
171+
| Optimize| IlxGen| IlGen| Output
155172
| Interactive// An error seen during interactive execution
156173

157174
/// Literal build phase subcategory strings.
@@ -320,9 +337,7 @@ type internal CompileThreadStatic =
320337
moduleErrorLoggerExtensions=
321338
openSystem.Reflection
322339

323-
// Instruct the exception not to reset itself when thrown again.
324-
// Design Note: This enables the compiler to prompt the user to send mail to fsbugs@microsoft.com,
325-
// by catching the exception, prompting and then propagating the exception with reraise.
340+
/// Instruct the exception not to reset itself when thrown again.
326341
letPreserveStackTrace(exn)=
327342
try
328343
letpreserveStackTrace= typeof<System.Exception>.GetMethod("InternalPreserveStackTrace", BindingFlags.Instance||| BindingFlags.NonPublic)
@@ -333,7 +348,7 @@ module ErrorLoggerExtensions =
333348
()
334349

335350

336-
// Reraise an exception if it is one we want to report to Watson.
351+
/// Reraise an exception if it is one we want to report to Watson.
337352
letReraiseIfWatsonable(exn:exn)=
338353
#if FX_REDUCED_EXCEPTIONS
339354
ignore exn
@@ -346,7 +361,7 @@ module ErrorLoggerExtensions =
346361
|:? System.IO.IOException->()// This covers FileNotFoundException and DirectoryNotFoundException
347362
|:? System.UnauthorizedAccessException->()
348363
| Failure_// This gives reports for compiler INTERNAL ERRORs
349-
|:? System.SystemException->
364+
|:? System.SystemException->
350365
PreserveStackTrace(exn)
351366
raise exn
352367
|_->()
@@ -362,13 +377,17 @@ module ErrorLoggerExtensions =
362377

363378
match exnwith
364379
| StopProcessing
365-
| ReportedError_-> raise exn
380+
| ReportedError_->
381+
PreserveStackTrace(exn)
382+
raise exn
366383
|_-> x.DiagnosticSink(PhasedDiagnostic.Create(exn,CompileThreadStatic.BuildPhase),true)
367384

368385
memberx.Warning exn=
369386
match exnwith
370387
| StopProcessing
371-
| ReportedError_-> raise exn
388+
| ReportedError_->
389+
PreserveStackTrace(exn)
390+
raise exn
372391
|_-> x.DiagnosticSink(PhasedDiagnostic.Create(exn,CompileThreadStatic.BuildPhase),false)
373392

374393
memberx.Error exn=
@@ -389,13 +408,16 @@ module ErrorLoggerExtensions =
389408
|:? System.Threading.ThreadAbortException| WrappedError((:? System.Threading.ThreadAbortException),_)->()
390409
#endif
391410
| ReportedError_| WrappedError(ReportedError_,_)->()
392-
| StopProcessing| WrappedError(StopProcessing,_)-> raise exn
411+
| StopProcessing| WrappedError(StopProcessing,_)->
412+
PreserveStackTrace(exn)
413+
raise exn
393414
|_->
394415
try
395416
x.ErrorR(AttachRange m exn)// may raise exceptions, e.g. an fsi error sink raises StopProcessing.
396417
ReraiseIfWatsonable(exn)
397418
with
398419
| ReportedError_| WrappedError(ReportedError_,_)->()
420+
399421
memberx.StopProcessingRecovery(exn:exn)(m:range)=
400422
// Do standard error recovery.
401423
// Additionally ignore/catch StopProcessing. [This is the only catch handler for StopProcessing].
@@ -408,6 +430,7 @@ module ErrorLoggerExtensions =
408430
with
409431
| StopProcessing| WrappedError(StopProcessing,_)->()// catch, e.g. raised by DiagnosticSink.
410432
| ReportedError_| WrappedError(ReportedError_,_)->()// catch, but not expected unless ErrorRecovery is changed.
433+
411434
memberx.ErrorRecoveryNoRange(exn:exn)=
412435
x.ErrorRecovery exn range0
413436

‎src/fsharp/InnerLambdasToTopLevelFuncs.fs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ let liftTLR = ref false
4242
letinternalError str= dprintf"Error:%s\n" str;raise(Failure str)
4343

4444
moduleZmap=
45-
letforce k mp(str,soK)=try Zmap.find k mpwith e-> dprintf"Zmap.force:%s%s\n" str(soK k); raise e
45+
letforce k mp(str,soK)=
46+
try Zmap.find k mp
47+
with e->
48+
dprintf"Zmap.force:%s%s\n" str(soK k);
49+
PreserveStackTrace(e)
50+
raise e
4651

4752
//-------------------------------------------------------------------------
4853
// misc

‎src/fsharp/TypeChecker.fs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,9 @@ let AnalyzeArbitraryExprAsEnumerable cenv (env: TcEnv) localAlloc m exprty expr
33293329
if (AddCxTypeMustSubsumeTypeUndoIfFailed env.DisplayEnv cenv.css m ty exprty) then
33303330
match tryType (mkCoerceExpr(expr,ty,expr.Range,exprty),ty) with
33313331
| Result res -> Some res
3332-
| Exception e -> raise e
3332+
| Exception e ->
3333+
PreserveStackTrace(e)
3334+
raise e
33333335
else None
33343336

33353337
// Next try to typecheck the thing as a sequence
@@ -3343,6 +3345,7 @@ let AnalyzeArbitraryExprAsEnumerable cenv (env: TcEnv) localAlloc m exprty expr
33433345
match probe ienumerable with
33443346
| Some res -> res
33453347
| None ->
3348+
PreserveStackTrace(e)
33463349
raise e
33473350

33483351

‎src/fsharp/vs/service.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,9 @@ module CompileHelpers =
20802080
for execin execsdo
20812081
match exec()with
20822082
| None->()
2083-
| Some exn-> raise exn
2083+
| Some exn->
2084+
PreserveStackTrace(exn)
2085+
raise exn
20842086

20852087
// Register the reflected definitions for the dynamically generated assembly
20862088
for resourcein ilxMainModule.Resources.AsListdo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp