Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix for #4956 (TP error reporting) #4978

Conversation

smoothdeveloper
Copy link
Contributor

issue #4956: Make Type Provider troubleshooting easier with better error reporting

Let the full exception details surface when a type provider fail at design / compile time.

Looking at the CI to get an idea of tests that need adjusting.

@smoothdeveloper
Copy link
Contributor Author

I'm checking the test output, the issue is that now the output contains the file path where the code was compiled from in the stacktrace, it looks like the tests are comparing the output for exact match.

For example:

neg1.fsx(3,18,3,70): typecheck error FS0001: This expression was expected to have type
    'string'    
but here has type
    'int'    

neg1.fsx(9,38,9,64): typecheck error FS3021: Unexpected exception from provided type 'FSharp.EvilProvider.IsArrayTypeRaisesException' member 'IsArray': The type provider 'Provider.EvilProvider' reported an error: System.Exception: deliberate error for testing purposes

   at <StartupCode$provider>.$Provider$fsx.Microsoft-FSharp-Core-CompilerServices-IProvidedNamespace-ResolveTypeName@130.Invoke(Unit _arg1)

   at System.Type.get_IsArray()

   at Microsoft.FSharp.Compiler.Tainted`1.Protect[a](FSharpFunc`2 f, range range) in C:\dev\projects\github.com\microsoft\visualfsharp4\src\fsharp\tainted.fs:line 94

notice C:\dev\projects\github.com\microsoft\visualfsharp4\src\fsharp\tainted.fs is part of the output.

How should I go about adjusting the tests with baseline?

@dsyme
Copy link
Contributor

dsyme commented May 24, 2018

@smoothdeveloper I suppose you'll need to modify the code that compares the output of the test andd the baseline

@dsyme
Copy link
Contributor

dsyme commented May 24, 2018

Somewhere around here I suppose: https://github.com/Microsoft/visualfsharp/blob/master/tests/fsharp/test-framework.fs#L448

So you should first update the baselines:

  1. run the tests on your local machine
  2. delete the *.bsl and *.vsbsl files for the failing tests and replace them by *.err and *.vserr)

There is already code these to diff out the current directory so perhaps you might not need to change anything

The actual call to the diffing routing is made here: https://github.com/Microsoft/visualfsharp/blob/master/tests/fsharp/single-test.fs#L215

Note you can run the tests from F# interactive

  1. build net40
  2. send the top 28 lines from https://github.com/Microsoft/visualfsharp/blob/master/tests/fsharp/tests.fs to F# Interactive
  3. Run test fragments like ``singleNegTest (testConfig "typecheck/sigs") "neg1"`

* add readme.md file to start accreting some useful information for the maintenance of the tests, gathered some of the tips that @dsyme mentioned
…ct a full stack trace

* added a substitution for <REPOSITORYROOT> for the filename in the stacktrace, baseline test relying on those have their .bsl files renamed to .bslpp
* add a readme.md in test folder
@smoothdeveloper
Copy link
Contributor Author

This is now passing, one drawback I see is for maintaining the tests in the future:

  • they assume windows path, I've kept the existing substitution logic (.bslpp), if that becomes an issue, we will need to improve that part a bit
  • if some of the fsharp code present in the stackframe changes, those tests will show the diff

I've gathered some information into a readme.md file that we should improve with more description and tips.

https://github.com/smoothdeveloper/visualfsharp/blob/a30a8da6a5c474f18f262f693f6726a979b464ab/tests/fsharp/readme.md

This comment gives an example of actual stacktrace: #4956 (comment) it will help type provider developers to set break points in the type provider SDK and figure out what is the problem they are facing.

@smoothdeveloper smoothdeveloper changed the title [wip] fix for #4956 (TP error reporting) fix for #4956 (TP error reporting) May 25, 2018
@smoothdeveloper
Copy link
Contributor Author

This shouldn't be merged for now: #4956 (comment)

@cartermp cartermp changed the title fix for #4956 (TP error reporting) [WIP] fix for #4956 (TP error reporting) Sep 20, 2018
@dsyme
Copy link
Contributor

dsyme commented Oct 25, 2018

@KevinRansom @cartermp I'd like some advice on this one

In general we don't want to show stack traces in error messages. But we do need to improve the diagnostics form TP developers and TP early adopters so they can see stack traces if they want.

So we should really have some kind of mechanism to "turn on stack traces for TP diagnostics". But what should it be? A VS IDE switch and command line flag seems too heavy but maybe it's what we need.

thanks

@KevinRansom
Copy link
Member

Can I get back to you on this ...

@dsyme
Copy link
Contributor

dsyme commented Oct 25, 2018

Can I get back to you on this ...

Yes, absolutely no rush

@baronfel
Copy link
Member

Something along these lines would be amazing. For TPs I work on I usually end up having a debug function that spams logs and catches/dumps stacktraces before rethrowing while I'm doing active development. Anything we can do to surface TP errors to TP developers would help demystify the whole process.

@smoothdeveloper
Copy link
Contributor Author

this is impacting fsprojects/FSharp.Data.SqlClient#262

I tend to agree that surfacing the whole stack trace is too crude and will freak out end users while this is, in essence, a library bug.

Anybody has idea how we could still get the full trace in DEBUG builds of provider? maybe a specifc define symbol that the compiler uses for TP design time assemblies, and make fsc/fsi pick the verbose message (corresponding to my PR)?

This will definitely help TP authoring, but we want to avoid kilometer long error by any means in release builds for TP consumers.

@smoothdeveloper
Copy link
Contributor Author

In general we don't want to show stack traces in error messages. But we do need to improve the diagnostics form TP developers and TP early adopters so they can see stack traces if they want.

Can we ease such decision by enabling the compiler to show stacktraces behind a flag like --surface-internal-errors?

this won't change anything for existing use of the compiler but provide easy escape hatch when this would really help diagnosis in various circumstances (mainly TP, compiler and tooling internal errors).

@KevinRansom
Copy link
Member

@dsyme , @smoothdeveloper , hey guys, is this PR going anywhere, I am trying to reduce the orphaned PR's in our repo.

Kevin

@smoothdeveloper
Copy link
Contributor Author

@KevinRansom I'm still in favor of having full stack trace to appear.

This is @dsyme comment:

exceptions are how TPs currently raise diagnostics, and we can't attach stack traces to those diagnostics.

@brettfo brettfo changed the base branch from master to main August 19, 2020 20:06
@KevinRansom
Copy link
Member

@dsyme , @smoothdeveloper , hey guys, is this PR going anywhere, I am trying to reduce the orphaned PR's in our repo.

Kevin

@KevinRansom
Copy link
Member

I discussed this with @cartermp and we decided to close it, we should address stack merging of inner exceptions somehow, but probably not this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants