Skip to content

An unscalable recipe reference fails the whole shopping list instead of warning #682

Closed

Description

@LeMyst

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::error rather than warning if the spec's "error" should come through, as long as it no longer aborts generate;
  • say how to fix it, e.g. "Skipped recipe reference 'Plats/Pâtes fraîches{600%g}': it has no yield in g, so it cannot be scaled to 300 g. Add yield: N%g to 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: shopping-list

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions