-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor: Improve error messaging in sidebar YAML parser #17229
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
Conversation
993869b
to
ec6174e
Compare
Hey @Dedelweiss, thank you very much for working on this! About the first point: check the code that calls |
ec6174e
to
80bfcd7
Compare
Hello @julienrf ! Thank you very much, it works perfectly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I left one comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility to create tests that cover this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just realized there are some problems with validation logic. I will get back to you with more precise information soon.
Yes, I'm currently working on it, sorry. |
fd43076
to
4a668a8
Compare
Edited: Just Added a new method to correct this. 👍 Hi, I'm working on the test and fixing the problem of the error message when the sidebar is correctly formatted.
Now I'm not sure if I missed any errors and I'm testing this.
I think because the title is missing, it goes to .fold and then to case _ in the toSidebar match. So I'm looking for a way to get a single error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding tests @Dedelweiss! I have left a couple of comments.
scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala
Outdated
Show resolved
Hide resolved
case RawInput(title, page, index, subsection, dir, hidden) => | ||
report.error(s"Error parsing YAML configuration file.\n$schemaMessage") | ||
if title.isEmpty() then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking this? title
is optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's optional for subsection
, - page
but not for a simple page
from what I have seen in my tests. Example:
- title: My title
page: my-page1.md
But I noticed that it works with an index before (it's just ignored), so I'm thinking of adding && index.isEmpty
.
- index: my-page2.md
page: my-page1.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one works too:
index: index.md
subsection:
- page: my-page1.md
page: my-page2.md
- page: my-page3.md
But the pages rendered are my-page2.md & my-page3.md
In this commit: - Added a error message when the path of a page is wrong - Added an error message when an inddex or a page path in a subsection is missing - Added an error message when a title in a subsection is missing
- Change the case match (Overkill) to a if else - Two types of messages : - Error: NoTitle and No index or No page. - Warning: When the parsing is not done correctly. Example: When a title got two pages.
- Error when a title but no pages
- Do a new method of test (Use a 'contains' instead) - Improve the accuracy of the error message by putting variables.
report.error(s"$msg\n$schemaMessage") | ||
else | ||
val msg = s"Error parsing YAML configuration file." | ||
report.warning(s"$msg\n$schemaMessage") | ||
Sidebar.Page(None, page, hidden) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we still return a Sidebar
even though we reported errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I think there's a problem with this return. Because we need to return the Sidebar
type but with Sidebar.Page(None, page, hidden)
. When a user forgets a page associated with a title like :
index: index.md
subsection :
- title : My title
- page: my-page2.md
This sends an error but also blocks the generation of all the documentation (which is rather extreme).
See if I can return Sidebar.Category(None, None, Nil, None) instead.
How is it that you know the sidebar is not valid, but you don’t know what is invalid? |
So, I think I've tested all the possible errors with a minimised code but I thought that the security of sending an error if a user didn't pass one of my conditions wouldn't be bad. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Lucas!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small nit.
case RawInput(title, page, index, subsection, dir, hidden) => | ||
report.error(s"Error parsing YAML configuration file.\n$schemaMessage") | ||
if title.isEmpty() && index.isEmpty() then | ||
val msg = "`title` property is missing for some page." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have access to page
up above here, can't we specify which page is actually missing the title
instead of just saying "some page"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understood this is not possible, see #17229 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small nit.
It seems the tests added in this PR fail on Windows, see https://github.com/lampepfl/dotty/actions/runs/5240593619/jobs/9461621127. @Dedelweiss, would you have time to look at the failures? |
Hello Julien, sure, I will look at it. |
The goal of this PR is to re-add the path validation of the page in a sidebar.yaml and improve the Testcase in the `SidebarParserTest` by erasing the first title, so it's easier to understand the problem in it. This PR is related to PRs: #17229 & #17959 [test_windows_full] Co-authored-by: Lucas Leblanc <[email protected]>
The goal of this PR is to re-add the path validation of the page in a sidebar.yaml and improve the Testcase in the `SidebarParserTest` by erasing the first title, so it's easier to understand the problem in it. This PR is related to PRs: #17229 & #17959 [test_windows_full] Co-authored-by: Lucas Leblanc <[email protected]> [Cherry-picked cf50fe3]
The goal of this PR is to re-add the path validation of the page in a sidebar.yaml and improve the Testcase in the `SidebarParserTest` by erasing the first title, so it's easier to understand the problem in it. This PR is related to PRs: #17229 & #17959 [test_windows_full] Co-authored-by: Lucas Leblanc <[email protected]> [Cherry-picked cf50fe3]
Validations
On this PR I added some errors for different conditions :
Error when a path in page is wrong
Error when an index or a page path for a title is missing
(It is therefore activated with the
title.isEmpty
condition. So far I've only found that when a user forgets a title it gives r = RawInput(,,,[],,false) in the toSidebar function. Thus, title.isEmpty is necessarily empty. However, if another error produces an r = RawInput(,,[],,false). This condition and its error message will no longer make sense. I am therefore less sure about this condition.)Error when a title for a page is missing
Warning when something is wrong but it does not interfere with the generation.
Tests
I added two functions in SidebarParserTest.
The purpose of these functions is to check if it contains the
schemaMessage
which is the general template sent in all error messages + the unique error message for each error.IE
I also noticed that @gringrape wanted to work on this issue, if a code has already been done on his side, I am quite open to resume the work started or to close my PR to leave his. I am also open to any suggestions for adding errors.
Fixes: #15326