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

Update AggregateException.xml #10396

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update AggregateException.xml #10396

wants to merge 2 commits into from

Conversation

epsitec
Copy link

@epsitec epsitec commented Sep 13, 2024

Related to dotnet/runtime#107743

Summary

Fixes an incorrect description of what method GetBaseException() does.

@epsitec epsitec requested a review from a team as a code owner September 13, 2024 06:12
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 13, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime

Copy link

Learn Build status updates of commit 0d6d7e9:

⚠️ Validation status: warnings

File Status Preview URL Details
xml/System/AggregateException.xml ⚠️Warning View Details

xml/System/AggregateException.xml

  • Line 0, Column 0: [Warning: xref-not-found - See documentation] Cross reference not found: 'Exception'.
  • Line 0, Column 0: [Warning: xref-not-found - See documentation] Cross reference not found: 'AggregateException'.

For more details, please refer to the build report.

Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.

For any questions, please:

xml/System/AggregateException.xml Outdated Show resolved Hide resolved
@@ -682,8 +682,8 @@
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns the <see cref="T:System.AggregateException" /> that is the root cause of this exception.</summary>
<returns>The <see cref="T:System.AggregateException" /> that is the root cause of this exception.</returns>
<summary>Returns the <see cref="Exception"/> that is the root cause of this exception. This will either be the root exception, or the first <see cref="AggregateException"/> that contains either multiple inner exceptions or no inner exceptions at all.</summary>
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as in dotnet/runtime#107743 (comment) : It is not clear what "root exception" means here.

Copy link
Author

Choose a reason for hiding this comment

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

@jkotas how would you make this clearer?

Copy link
Member

Choose a reason for hiding this comment

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

Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Copy link

Learn Build status updates of commit 4f513d6:

✅ Validation status: passed

File Status Preview URL Details
xml/System/AggregateException.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Comment on lines +685 to +686
<summary>Returns the <see cref="T:System.Exception"/> that is the root cause of this exception. This exception is either the root exception or the first <see cref="T:System.AggregateException"/> that contains either multiple inner exceptions or no inner exceptions at all.</summary>
<returns>The <see cref="T:System.Exception" /> that is the root cause of this exception.</returns>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<summary>Returns the <see cref="T:System.Exception"/> that is the root cause of this exception. This exception is either the root exception or the first <see cref="T:System.AggregateException"/> that contains either multiple inner exceptions or no inner exceptions at all.</summary>
<returns>The <see cref="T:System.Exception" /> that is the root cause of this exception.</returns>
<summary>Returns the <see cref="T:System.AggregateException"/> that is the root cause of this exception. This exception is either the current exception or the first <see cref="T:System.AggregateException"/> that contains either multiple inner exceptions or no inner exceptions at all.</summary>
<returns>The <see cref="T:System.AggregateException" /> that is the root cause of this exception.</returns>

https://learn.microsoft.com/en-us/dotnet/api/system.exception.getbaseexception and other docs use "current exception" for this.

Also, I think the original docs were better in highlighting that the returned instance is always AggregateException.

Copy link
Author

Choose a reason for hiding this comment

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

The original docs were wrong, hence my fixes. The code will return the plain Exception which was thrown up the chain (what's now called the current exception), and only if there are multiple exceptions wrapped in an AggregateException will it return an aggregate exception. That's the whole point of this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, I have misread how the implementation behaves.

I agree with you that the return type in the docs is wrong.

I am not sure whether it makes sense to try to describe the exact algorithm used by this method in the docs. The current implementation of Exception.GetBaseException and AggregateException.GetBaseException methods are in conflict with the contract for these methods described in the docs.

https://learn.microsoft.com/en-us/dotnet/api/system.exception.getbaseexception?view=net-8.0 says "For all exceptions in a chain of exceptions, the GetBaseException method must return the same object (the base exception).". For example, this invariant does not seem to hold for

TargetInvocationException 
   -> AggregateException
          -> ArgumentException
          -> ArgumentException

GetBaseException() called on TargetInvocationException returns first ArgumentException for , but GetBaseException() called on AggregateException returns the same AggregateException.

We may want to fix the implementation and/or docs to make this more sensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants