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

TypeProviders: Add inner base-exception description #17251

Merged
merged 7 commits into from
Jun 27, 2024

Conversation

Thorium
Copy link
Contributor

@Thorium Thorium commented May 25, 2024

As @smoothdeveloper PR #4978 from 2018 is still not not accepted,
this tries to be the simplest possible fix for the existing issue #17249

@Thorium Thorium requested a review from a team as a code owner May 25, 2024 14:00
Copy link
Contributor

github-actions bot commented May 25, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

@Thorium
Copy link
Contributor Author

Thorium commented May 25, 2024

Before this PR, from the current error message, I had no idea which file was missing.
Tested with this PR's F# compiler and this actually helps telling the error (duckdb.dll missing in this case).
image

Copy link
Contributor

@abelbraaksma abelbraaksma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! A few nits, nothing major. It would be nice if there were test cases for this... (but imo no need to add them now).

Thorium and others added 3 commits May 26, 2024 00:46
Thanks @abelbraaksma

Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
@abelbraaksma
Copy link
Contributor

abelbraaksma commented May 26, 2024

@Thorium About this comment: #17251 (comment)

I just realize that GetBaseException() is virtual. Which means it could be overridden and, even though for built-in .NET exception classes, this does not misbehave anymore and has been fixed since, there's still the (slight) possibility that any derived class returns null, or something other than the deepest inner exception.

Which means, in turn, that your code is not safe currently for the same reasons you stated. I propose to get around this as follows, just add a function like the following, and use that instead:

[<TailCall>]
let rec getMostInnerException (ex: exn) =
    if isNull ex then 
        // should never happen, we are in a try-with (we may consider throwing instead of returning?)
        ArgumentNullException("Unreachable code. Caught exception is null", nameof ex) :> exn
    else
        if isNull ex.InnerException then ex
        else getMostInnerException ex.InnerException

Oh, and @smoothdeveloper had a #17251 (comment) that got buried a bit. to his point, I'd argue that the current change is already an improvement, but showing the entire stacktrace in the tooltip blob can easily take the whole screen and be disruptive. While I agree that it is useful, we may want to think about that a little first.

@Thorium
Copy link
Contributor Author

Thorium commented May 26, 2024

No the ex it's not null itself, but the inner one is.

@abelbraaksma
Copy link
Contributor

abelbraaksma commented May 26, 2024

No the ex it's not null itself, but the inner one is.

@Thorium Yes, but that won't change how GetBaseException works (i.e., try (exn "foo").GetBaseException(), it doesn't have an inner exception, but works as expected and returns the current ex). It'll never return null even if InnerException is null.

My point was more about a user-overridden GetBaseException can only ever return null if it breaks the contract, but unfortunately, we don't know that, so we should not use it. Hence my suggestion above.

Copy link
Contributor

@abelbraaksma abelbraaksma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous trains of thought may have been confusing, in part because I wasn't entirely correct. It is subtle. Please check my new comments, I think only the changes in line 108 are actually needed.

@edgarfgp
Copy link
Contributor

edgarfgp commented Jun 26, 2024

Anything blocking this PR ? Looks a good improvement when working with TP cc @psfinaki

Copy link
Contributor

@abelbraaksma abelbraaksma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Thorium, thanks for taking the time to address my suggestions and patiently explaining your approach and choices.

I think one day we have to revisit e.GetBaseException(), as it skips over any and all exceptions between top and bottom, and I originally thought your PR was about getting the first inner exception of the tree. But that doesn't have to be addressed now.

Be as it may, I never meant to block this, but real life caught up and I wasn't notified anymore, until @psfinaki reminded me.

Let's get this in. I think it is a great improvement over what we had originally.

@psfinaki
Copy link
Member

Well thanks @edgarfgp for reminding rather :)

Thanks @Thorium, merging!

@psfinaki psfinaki enabled auto-merge (squash) June 27, 2024 11:17
@psfinaki
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

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

Successfully merging this pull request may close these issues.

7 participants