Repository navigation
Description
What happens
One recipe reference that cannot be scaled to a unit takes down the whole shopping list. A recipe written for 4:
---
servings: 4
---
Cook @./Plats/Pâtes fraîches{600%g} ...
where Plats/Pâtes fraîches.cook declares servings: 4 but no yield. Add the carbonara to the shopping list for 2 servings and the list is replaced by:
cannot expand recipe reference 'Plats/Pâtes fraîches': cannot scale to 300 g: Cannot scale recipe: yield metadata is missing or invalid
Nothing else is listed: not the guanciale, not the pecorino, not the other recipes on the list. cook shopping-list fails the same way.
Why it should not stop the list
The spec does say a unit reference with no matching yield is an error. That makes the reference wrong. It does not make the rest of the list wrong, and the other references that cannot be followed already get reported without stopping anything. In ExpandRefs::expand (crates/core/src/shopping_list/mod.rs), a reference that points outside the recipe directory, one nested deeper than MAX_REFERENCE_DEPTH, and a circular one each push a Diagnostic attributed to the recipe and continue. The unit-scaling failure, a few lines further down, is the only one that returns CoreError::Reference (and so is quantity is not a number, right next to it).
It is also easy to get into without noticing. yield only works as number%unit with no space (yield: 600 g fails too), and a recipe that worked as a reference with no quantity breaks the list the day someone adds a quantity to that reference.
Proposal
Treat it like its neighbours:
- push a diagnostic attributed to the recipe that holds the reference, and keep going with the rest of the list. It could be
Diagnostic::errorrather thanwarningif the spec's "error" should come through, as long as it no longer abortsgenerate; - say how to fix it, e.g. "Skipped recipe reference 'Plats/Pâtes fraîches{600%g}': it has no
yieldin g, so it cannot be scaled to 300 g. Addyield: N%gto Plats/Pâtes fraîches.cook, or reference it by{N%servings}or by a plain factor. Anything it would have added is not on the list"; - the same for
quantity is not a number.
An alternative to dropping the reference's ingredients is to list the reference itself as an item (Pâtes fraîches: 300 g), which is still something you can shop for. Skipping is closer to what the other three warnings do, though.
CoreError::Reference would then only be returned by callers that really cannot go on, and the # Errors section of generate changes to match.
Activity
fix(web): show the shopping list's warnings on the page
fix(web): word the shopping list warning in the page's language
fix(web): name the recipe in a shopping list warning with / on Window…
fix(shopping-list): list a reference that cannot be scaled instead of…
fix(web): show the shopping list's warnings on the page
fix(web): word the shopping list warning in the page's language
fix(web): name the recipe in a shopping list warning with / on Window…
fix(shopping-list): list a reference that cannot be scaled instead of…
fix(web): show the shopping list's warnings on the page
fix(web): word the shopping list warning in the page's language
fix(web): name the recipe in a shopping list warning with / on Window…
fix(shopping-list): list a reference that cannot be scaled instead of…