Recipe 05 / Debug a recipe

Find the missing assumption.

When a recipe fails, changing every ingredient hides the cause. Reduce the problem to one example and ask the assistant to trace the value that first becomes incorrect.

Result: A reproducible diagnosisGo to method
  1. Write down the mismatch

    Suppose a count arrives as the string "10" and adding 2 produces "102". Preserve the original input type in the reproduction. If you silently rewrite the input as a number, the demonstration stops showing the defect. Record the actual output, expected output, and relevant runtime before requesting a fix.

  2. Trace before seasoning

    Ask where the value enters the program and where its type should become a number. Inspect the parser and callers instead of inserting conversions throughout the code. Decide how empty strings, decimals, negative counts, and values beyond the safe integer range should behave. Those are requirements to settle, not edge cases to guess away.

  3. Keep a regression example

    Once the boundary is clear, make one focused change and retain the original failing case as a test. Add the invalid-input cases that your chosen contract requires. Run the relevant checks and compare the new behavior with the intended result. A useful diagnosis explains both why the old behavior occurred and why the fix belongs at that boundary.

The reproduction

const incomingCount = '10';
const actual = incomingCount + 2;
console.log({ inputType: typeof incomingCount, actual, expected: 12 });
// actual is "102": the + operation concatenates a string.

The serving check

The original input now produces the intended result, and invalid inputs follow an explicit rule rather than an accidental conversion.

A brief for your assistant

Trace the count from input to addition. Explain why "10" plus 2 yields "102". Propose where validation and numeric conversion belong, with rules for empty and invalid input. Do not edit until the contract is clear.
Next at the counterMise en place