-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(frontmatter): improve duplicate frontmatter key error handling #7679
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
base: main
Are you sure you want to change the base?
fix(frontmatter): improve duplicate frontmatter key error handling #7679
Conversation
martinjagodic
left a 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.
This correctly prints to the console which key is duplicated on which line. It's frustrating that it doesn't tell me which file is affected in the collection view, so I have to guess that. It also breaks loading of affected entries - I get an empty card in the collection view if it's affected. I'm testing this on a large collection and my console is bobmarded with these messages
- Don't throw an error - this will enable the title to be displayed on the collection view even if an entry is affected. Show a warning instead, don't include a stack trace.
- Add info about the affected file along with the key and line number
- When an entry is open in Editor mode, only show errors for that file, not every file in the collection.
To discuss:
Should we display a warning to the user? If they are not a developer, they will have no control over this, so it could be annoying. However, this would be an effective way to fund such issues.
|
Thanks for the feedback. ill update it now.
I’ll push the changes soon. |
martinjagodic
left a 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.
This is better now. For me, all files return as unknown while testing locally with decap proxy.
Warnings in the console are ok now. I noticed another problem: there are false positives when the same key appears on several levels. For example
title: root title
object:
title: object title
will give an error that title is a duplicate on line 3, even though it should be fine.
Also, make sure that all tests are passing.
|
Alright now I get it. I'll now -parse yaml structure properly |
|
do tell if any changes are needed. |
martinjagodic
left a 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.
To make duplicate-key detection more robust and precise, please leverage the yaml parser’s built-in diagnostics instead of manual checks.
Concretely:
- Use
yaml.parseDocument(src, { uniqueKeys: true, prettyErrors: true }). - Inspect
doc.errors/doc.warnings
This way, we can also pretty print any other formatting problems, not just duplicate keys.
Note: we had js-yaml and yaml both used in this project, but since #7684 we only have yaml.
Summary
I fixed an issue with YAML frontmatter where duplicate keys caused a vague error that didn’t point to the real problem. I added a simple check that detects repeated keys and shows a clear message with the key name and line number which points to the file
Test plan
-ensured normal frontmatter files still parse correctly.
-ran the formatter manually to confirm it now identifies the duplicated key.
-verified that the error message displays the correct key and the line where it occurs.
Checklist
Please add a
xinside each checkbox: