Repository navigation
fix(parser): suppress spurious type warning on >> numeric metadata - #743
Conversation
LeMyst
left a comment
There was a problem hiding this comment.
Thanks for looking into this. The spurious warning is real, but this change hides real warnings and accepts values that don't work.
1. It hides the real "Time overridden" warning
The time keys are included at crates/core/src/parser.rs:43, but >> time: 30 never warned in the first place: parse_time falls back to parsing a float. For those keys, calling run_std_checks(false) also skips locations.metadata.insert and the time-override check in cooklang's event consumer. So >> time: 30 together with >> prep time: 10 used to warn "Time overridden" and no longer does.
2. The re-parse is looser than the code that reads the value
parser.rs:47 re-parses with serde_yaml, so >> servings: 4 # x (and front matter servings: "4 # x") now validates without a warning. But Metadata::servings() uses s.parse::<u32>() and returns Text("4 # x"), so scaling by servings silently stops working.
3. The scope is wider than the description
The metadata validator also runs for YAML front matter, so quoted servings: "4" stops warning too. That one is harmless, because servings() accepts it, but the PR text says only >> is affected.
Suggested fix
Restrict the override to StdKey::Servings and check with value_str.parse::<u32>().is_ok(), which matches servings() exactly.
The underlying inconsistency is in cooklang-rs: check_std_entry uses as_u32(), while Metadata::servings() accepts numeric strings. That deserves an issue upstream so this workaround can eventually go. The LSP and cook report don't go through parse_options(), so the editor will keep showing the warning in the meantime.
This conflicts with #742 in all four shared files (adjacent lines). Both PRs patch three copies of the same PARSER.parse call, which suggests one shared helper (BOM strip plus options) used by parse_unscaled, doctor's validate_entry and util::parse_unscaled_recipe_from_entry.
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
5bddd82 to
03a73d8
Compare
|
Reworked per review: the validator now touches only |
A >> metadata value reaches the std checks as a YAML string, so ">> servings: 4" warned "Unsupported value for key" even though Metadata::servings() accepts it. Suppress the std check for a servings entry only when its value parses to a u32 — the same test servings() itself applies — so bad values and every other key's warnings (e.g. "Time overridden") are unaffected. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
03a73d8 to
9ea1011
Compare
|
Thanks for the rework. I checked the cases from the first review. One thing left, for whoever merges second: this still conflicts with #742 in all four files, because both add their own options to the same three 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
|
Noted — the conflict with #742 is all in the same three |
Closes #713
A
>>metadata value always reaches upstream's std checks as a YAML string, so>> servings: 4warnedUnsupported value for key: 'servings'("expected 'number' but got 'string'").Adds a
parse_options()factory with ametadata_validatorthat suppresses the std check only for aservingsentry whose value parses asu32— exactly whatMetadata::servings()applies. Nothing else is touched:>> servings: manyand>> servings: 4 # xstill warn (a YAML re-parse would have wrongly accepted the latter, whichservings()itself rejects), and the time keys keep their real warnings like "Time overridden". All three recipe-parse entry points (parse_unscaled, doctor validation,parse_unscaled_recipe_from_entry) share the options.Test plan
legacy_numeric_metadata_does_not_warn— no type warning, deprecation warning keptlegacy_bad_numeric_metadata_still_warns—manyand4 # xstill warnlegacy_time_override_warning_is_preserved—time+prep timestill warns "Time overridden"cargo test -p cookcli-coregreen