Reproduce a bug with a minimal failing input
Quick answer
Effective debugging starts with an observable discrepancy: a specific input, an expected result and the actual result. Reduce the case without losing the failure so that experiments are easy to repeat.
How it works
Record the runtime, relevant configuration and steps. Construct a minimal input that still fails; remove unrelated fields one at a time. Write an assertion for the intended result before changing the implementation. Distinguish syntax errors, exceptions and incorrect successful results. Inspect one hypothesis at a time and retain a failing regression test after the fix. Examples below deliberately expose a logic error without throwing.
Local examples
Run in Node.js v22.16.0 as a CommonJS script. No interactive debugger attached; actual ByteMind editor support is unverified.
(async () => {const count=xs=>xs.slice(1).length; console.log(count(["a"]),1,count(["a"])===1);})()Expected console output:
0 1 falseA one-item input exposes the dropped first item.
Run in Node.js v22.16.0 as a CommonJS script. No interactive debugger attached; actual ByteMind editor support is unverified.
(async () => {const assert=require("node:assert/strict"); const count=xs=>xs.length; assert.strictEqual(count(["a"]),1); assert.strictEqual(count([]),0); console.log("fixed");})()Expected console output:
fixedBoth the minimal failing case and empty case now satisfy the contract.
Common mistakes
Do not change several unrelated functions at once or delete the only failing case.
Practice
Minimize the input for an off-by-one loop and verify that the smallest failing case passes after the fix.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reproduce a bug with a minimal failing input — Knowledge Check
Apply the concept and reason about local example output.
Which evidence makes a bug report actionable?
What must remain true when minimizing a failing input?
Why retain the failing case after a repair?
What is the exact console output in Reproduce a bug with a minimal failing input example 1?
(async () => {const count=xs=>xs.slice(1).length; console.log(count(["a"]),1,count(["a"])===1);})()What is the exact console output in Reproduce a bug with a minimal failing input example 2?
(async () => {const assert=require("node:assert/strict"); const count=xs=>xs.length; assert.strictEqual(count(["a"]),1); assert.strictEqual(count([]),0); console.log("fixed");})()