Skip to content

fix(shopping-list): list a reference that cannot be scaled instead of failing - #684

Merged
LeMyst merged 4 commits into
cooklang:mainfrom
LeMyst:fix/unscalable-reference
Oct 11, 2026
Merged

LeMyst merged 4 commits into
cooklang:mainfrom
LeMyst:fix/unscalable-reference

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #682.

What changes

A recipe reference that asks for an amount its recipe cannot be scaled to no longer fails the shopping list. This covers @./Plats/Pâtes fraîches{600%g} against a recipe with no yield, a {6%servings} against one with no whole-number servings, a yield in another unit, and an amount that is not a number. Instead:

  • the reference goes on the list as written, at its holder's scale: the item --ignore-references would make of it (Pâtes fraîches: 300 g for a carbonara made for two). It stays optional if the reference was @?;
  • a warning attributed to the recipe that holds the reference says what to change;
  • nothing below the reference is expanded, so the unwrap_or(1.0) fallback after target_factor stays unreachable, as the existing tests require.

Everything else on the list is there as before. Before, the CLI and the web list both stopped at:

cannot expand recipe reference 'Plats/Pâtes fraîches': cannot scale to 300 g: Cannot scale recipe: yield metadata is missing or invalid

Now (cook shopping-list "Plats/Pâtes à la Carbonara.cook:0.5", exit 0):

 WARN …/Plats/Pâtes à la Carbonara.cook: Could not scale recipe reference 'Plats/Pâtes fraîches' to 300 g: it has no yield to scale from. Add how much it makes, written number%unit, such as `yield: 500%g`. It is on the list as written, not as the recipe's ingredients
[other]
guanciale      100 g
Pâtes fraîches 300 g

On the shopping list page, in the page's language

The warning used to reach only the server's log, so the web list showed Pâtes fraîches 300 g with no word on why the pasta's flour and eggs were missing.

  • Core also describes the warning in parts: Diagnostic::kind, DiagnosticKind::UnscalableReference { reference, amount, cause }, where UnscalableCause is NotANumber, NoServings, NoYield { unit } or YieldInOtherUnit { unit }. Both enums are #[non_exhaustive], and message keeps the English text for the CLI and any other caller.
  • POST /api/shopping_list now sends warnings. Each line starts with the path of the recipe holding the reference, made relative to the recipe directory through private_paths::hide, and is worded in the request's language (lang cookie, then Accept-Language). There are four messages per locale (shopping-warning-*), one per cause, and duplicates are dropped.
  • The shopping list page shows them above the list in a banner like the aisle page's, under the heading shopping-warnings.

Shopping list page in French with a banner above the list, in French, explaining that Pâtes fraîches could not be scaled to 300 g

Phone width The same page at phone width

The message names the number%unit form because yield: 600 g looks right and does not parse as a yield. "missing or invalid" never said that.

Choices to review

  • Listed, not skipped. An unscalable recipe reference fails the whole shopping list instead of warning #682 leaned towards skipping the reference like the cycle, depth and outside-the-directory warnings do. Listing it keeps it in front of whoever reads only the list: a copied or printed list carries no banner. And what it names (fresh pasta, a sauce) is still something to buy or make.
  • Only warnings core describes in parts reach the page, for now this one. The recipes' parse warnings stay in the log: they are for the recipe page and cook doctor. One of them is cooklang 0.19 reading yield as a synonym of servings and objecting to the very yield: 600%g this warning asks for (cooklang-rs#131 makes yield a key of its own). The cycle and depth warnings could get a kind and a message too, in a follow-up.
  • A warning, not an error-severity diagnostic. The spec calls a unit reference without a matching yield "an error". It is one, but of the reference: the list it sits in is still correct for everything else. A Severity::Error would make Outcome::has_errors call the whole list a failure, which is what this PR removes. Happy to switch if you read the spec the other way.
  • CoreError::Reference is removed. Nothing can return it any more, and CircularReference went the same way (6d47145) for the reason the comment in error.rs gives. That is a breaking change for cookcli-core consumers who match on it.

Parse failures and missing recipes below a reference still fail the list (CoreError::Parse / RecipeNotFound), unchanged.

Tests

tests/shopping_list_warnings_test.rs (spawned server):

  • the warning reaches warnings, is named after the recipe holding the reference, relative to the recipe directory, and contains no server path;
  • it is in French for Accept-Language: fr-FR;
  • a recipe with yield: 600%g sends no warning, even though cooklang warns about the yield key;
  • a clean list sends [], and the same warning from the same recipe twice is sent once.

The core tests also check kind for each of the four causes.

crates/core/src/shopping_list/tests.rs: the four tests that pinned CoreError::Reference now pin the listed item, the warning and that nothing below is expanded. New cases cover other recipes still being listed, the holder's scale (the 300 g carbonara case), attribution to the recipe deeper down that holds the reference, an amount that is not a number, and an optional reference.

cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace are clean. docs/api.md is regenerated. I checked the page in Chromium (Playwright) on the carbonara case at desktop and phone width.

🤖 Generated with Claude Code

LeMyst and others added 4 commits October 11, 2026 23:44
… failing

A recipe reference asking for an amount its recipe cannot be scaled to —
`@./pasta{600%g}` when the pasta recipe has no `yield`, servings when it
declares none — failed the whole shopping list: every other recipe on it
went too, in the CLI and on the web page alike.

The spec calls such a reference an error, and it is one, but of the
reference, not of the list. Put the reference on the list as written, the
item `--ignore-references` would make of it (`pasta: 300 g`), and raise a
warning attributed to the recipe holding it that says what to write —
`yield` only works as `number%unit`, which "yield metadata is missing or
invalid" did not say. Nothing below the reference is expanded, so the
factor `target_factor` could not work out still reaches nothing.

Listed rather than skipped like a cycle: the web list does not show
warnings, so a skipped reference would vanish without a word there.

`CoreError::Reference` can no longer be returned, so it goes, as
`CircularReference` did.

Closes cooklang#682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reference its recipe cannot be scaled for is now listed as written, but
the warning saying so reached only the server's log: the page showed
"Pâtes fraîches 300 g" with no word on why the pasta's flour and eggs
were missing.

POST /api/shopping_list now sends `warnings`, one `recipe: message` line
per diagnostic the recipes raised (hints left out, duplicates dropped,
paths relative to the recipe directory through private_paths::hide), and
the shopping list page shows them above the list in a banner like the
aisle page's, under a heading translated into every locale.

Refs cooklang#682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The banner showed core's English message under a translated heading.
Core now describes the warning in parts as well — `Diagnostic::kind`,
`DiagnosticKind::UnscalableReference { reference, amount, cause }` — and
the server words it in the request's language (lang cookie, then
Accept-Language) from four messages per locale, one per cause.

The banner now shows only warnings described that way. The recipes'
parse warnings stay in the log: they are for the recipe page and
`cook doctor`, and one of them is cooklang 0.19 reading `yield` as a
synonym of `servings` and objecting to the very `yield: 600%g` the
warning asks for (cooklang-rs#131 makes yield its own key).

Refs cooklang#682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s too

The warning started with Plats\Carbonara.cook on Windows, where every
other recipe path the API sends, and the reference named in the same
line, uses /.

Refs cooklang#682

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst force-pushed the fix/unscalable-reference branch from 8fcfe5c to 0f2b11a Compare October 11, 2026 22:06
@LeMyst
LeMyst merged commit 538a85b into cooklang:main Oct 11, 2026
5 checks passed
@LeMyst
LeMyst deleted the fix/unscalable-reference branch October 11, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant