Repository navigation
fix(shopping-list): list a reference that cannot be scaled instead of failing - #684
Merged
Merged
Conversation
LeMyst
marked this pull request as ready for review
October 11, 2026 15:17
LeMyst
force-pushed
the
fix/unscalable-reference
branch
from
October 11, 2026 17:01
40721a9 to
8fcfe5c
Compare
… 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
force-pushed
the
fix/unscalable-reference
branch
from
October 11, 2026 22:06
8fcfe5c to
0f2b11a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 noyield, a{6%servings}against one with no whole-numberservings, a yield in another unit, and an amount that is not a number. Instead:--ignore-referenceswould make of it (Pâtes fraîches: 300 gfor a carbonara made for two). It stays optional if the reference was@?;unwrap_or(1.0)fallback aftertarget_factorstays 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:
Now (
cook shopping-list "Plats/Pâtes à la Carbonara.cook:0.5", exit 0):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 gwith no word on why the pasta's flour and eggs were missing.Diagnostic::kind,DiagnosticKind::UnscalableReference { reference, amount, cause }, whereUnscalableCauseisNotANumber,NoServings,NoYield { unit }orYieldInOtherUnit { unit }. Both enums are#[non_exhaustive], andmessagekeeps the English text for the CLI and any other caller.POST /api/shopping_listnow sendswarnings. Each line starts with the path of the recipe holding the reference, made relative to the recipe directory throughprivate_paths::hide, and is worded in the request's language (langcookie, thenAccept-Language). There are four messages per locale (shopping-warning-*), one per cause, and duplicates are dropped.shopping-warnings.Phone width
The message names the
number%unitform becauseyield: 600 glooks right and does not parse as a yield. "missing or invalid" never said that.Choices to review
cook doctor. One of them is cooklang 0.19 readingyieldas a synonym ofservingsand objecting to the veryyield: 600%gthis warning asks for (cooklang-rs#131 makesyielda key of its own). The cycle and depth warnings could get akindand a message too, in a follow-up.yield"an error". It is one, but of the reference: the list it sits in is still correct for everything else. ASeverity::Errorwould makeOutcome::has_errorscall the whole list a failure, which is what this PR removes. Happy to switch if you read the spec the other way.CoreError::Referenceis removed. Nothing can return it any more, andCircularReferencewent the same way (6d47145) for the reason the comment inerror.rsgives. That is a breaking change forcookcli-coreconsumers 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):warnings, is named after the recipe holding the reference, relative to the recipe directory, and contains no server path;Accept-Language: fr-FR;yield: 600%gsends no warning, even though cooklang warns about theyieldkey;[], and the same warning from the same recipe twice is sent once.The core tests also check
kindfor each of the four causes.crates/core/src/shopping_list/tests.rs: the four tests that pinnedCoreError::Referencenow 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-targetsandcargo test --workspaceare clean.docs/api.mdis regenerated. I checked the page in Chromium (Playwright) on the carbonara case at desktop and phone width.🤖 Generated with Claude Code