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

chore: Fix exception thrown on TOC loading internally #9974

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

filzrev
Copy link
Contributor

@filzrev filzrev commented May 31, 2024

This PR is intended to fix internal exception that occurred when deserializing toc.yml file.

Current docfx implementation use YamlDeserializerWithFallback class to deserialize toc.yml file.
And following operation executed.

  1. Try to deserialize yml as List<TocItemViewModel>.
  2. If YamlException is thrown. then deserialize as TocItemViewModel.

This PR intended to fix following problems.

  • On current implementation try-catch logics are used when deserializing TocItemViewModel as List<TocItemViewModel> .
    -> Exceptions should not be thrown in the normal execution flow.
  • When deserializing as TocItemViewModel. It requires to open safe file twice.

@filzrev filzrev changed the title chore: Fix internal exception on TOC loading chore: Fix exception thrown on TOC loading internally May 31, 2024
@filzrev filzrev force-pushed the chore-fix-internal-exception-on-toc-loading branch from 16d74d0 to 76497b3 Compare May 31, 2024 13:57
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.81%. Comparing base (fe673ec) to head (9d56541).
Report is 211 commits behind head on main.

Files Patch % Lines
src/Docfx.Build/TableOfContents/TocHelper.cs 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9974      +/-   ##
==========================================
+ Coverage   74.31%   78.81%   +4.49%     
==========================================
  Files         536      539       +3     
  Lines       23189    23440     +251     
  Branches     4056     4063       +7     
==========================================
+ Hits        17234    18474    +1240     
+ Misses       4853     3822    -1031     
- Partials     1102     1144      +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -86,7 +86,45 @@ public static TocItemViewModel LoadSingleToc(string file)
Logger.LogError(message, code: ErrorCodes.Toc.InvalidTocFile);
throw new DocumentException(message, e);
}
}

private static bool IsListTocItems(StreamReader reader)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit complicated. For handling YAML, I'm leaning towards we move to a future where YAML are parsed into a JSON node tree, and then deserialized to objects with standard JsonConverter.

Similar to https://github.com/dotnet/docfx/blob/v3/src/docfx/lib/json/YamlUtility.cs#L112 but with System.Text.Json.

Copy link
Contributor Author

@filzrev filzrev Jun 20, 2024

Choose a reason for hiding this comment

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

This looks a bit complicated.

Remove stream relating unwind logics.
Instead, Read entire YAML text first, and then determine TOC type by YAML Parser.

@filzrev filzrev force-pushed the chore-fix-internal-exception-on-toc-loading branch from 280054a to 323b0ce Compare October 21, 2024 10:01
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.

2 participants