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

Automatically document exceptions on methods based on methods it's calling #3983

Open
pascalberger opened this issue Jan 28, 2019 · 5 comments
Labels
dotnet: xml-comment XML comment for .NET API reference docs dotnet Generate .NET API reference docs

Comments

@pascalberger
Copy link
Member

DocFX Version Used:
2.40.7

Template used: (default or statictoc or contain custom template)
default

Steps to Reproduce:

n/a

Expected Behavior:

It would be nice to have the possibility that DocFx could automatically document exceptions on a method based on the documented exceptions on methods it's calling.

Actual Behavior:

Currently I can document possible exception using the exception XML comment tag. This needs to be done manually on all methods, which is duplicated work if exceptions thrown in methods called by the method should also be documented.

@pascalberger
Copy link
Member Author

@BillWagner

@yufeih
Copy link
Contributor

yufeih commented Jan 29, 2019

To do this, docfx needs to consume a static call graph of every method. Currently the csharp compiler does not produce that static call graph, and I doubt if it could if you consider non-static class like delegates, interface calls, virtual calls...

This feels unlikely to happen unless charp has checked exceptions

@BillWagner
Copy link
Member

I was chatting with @pascalberger about this request during the C# workshop at NDC. We were wondering if there is a simpler feature that provides a lot of the benefit with much less engineering work for docfx (and the language).

@yufeih is correct that to completely solve the problem you'd need checked exceptions, and you'd still need to make assumptions about the environment and the stability of everything in the system. That's clearly out of scope.

Instead, consider if docfx or the compiler could build a static call graph that only went as deep as the methods in the current assembly. Then, the <exceptions> section could include the union of the exceptions from those methods.

Consider this as the key scenario:

  1. I create a DoesImportantWork() method. I quickly find that there are 3 common overloads with different arguments. Maybe one takes a struct that has all the necessary information, another has individual arguments for that information, a third gets the needed information from the environment.

As an implementation detail, all three of those methods are implemented in one of the overloads. That implies that the list of exceptions possible could be taken from that one method declaration. As implemented today, developers need to copy and paste that common exception list into all the overloads. A feature that solved just that scenario would be very valuable.

@stale
Copy link

stale bot commented May 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the stale label May 2, 2019
@stale stale bot removed the stale label May 6, 2019
@superyyrrzz superyyrrzz added the dotnet Generate .NET API reference docs label May 6, 2019
@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented May 10, 2019

If DocFX supported the cref and select attributes of inheritdoc (#1306), one could use that.

/// <exception cref="FileNotFoundException">
///  There is no file at <paramref name="path"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
///  <paramref name="fudgeFactor"/> is not positive.
/// </exception>
void DoesImportantWork(string path, float fudgeFactor)
{
    // …
}

/// <inheritdoc cref="DoesImportantWork(string, float)"
///             select="exception[not(.//paramref/@name='fudgeFactor')]"/>
void DoesImportantWork(string path)
{
    DoesImportantWork(path, 1.0);
}

This also demonstrates that not all exceptions apply to all overloads.

@superyyrrzz superyyrrzz added dotnet: xml-comment XML comment for .NET API reference docs and removed dotnet Generate .NET API reference docs labels May 14, 2019
@yufeih yufeih added dotnet Generate .NET API reference docs and removed proposal labels Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet: xml-comment XML comment for .NET API reference docs dotnet Generate .NET API reference docs
Projects
None yet
Development

No branches or pull requests

5 participants