Find and fix errors
Send the error message with the related function, and have Claude Sonnet 5.5 explain which line it comes from and why, then give the smallest fix and a test that reproduces the problem.
Example: What’s causing this error?
Material
- Error
- TypeError: Cannot read properties of undefined (reading 'price')
- cart.ts
- const total = items.reduce((sum, id) => sum + catalog[id].price, 0);
- What we see
- One item in the cart has been discontinued.
PromptFrom the error and the function, explain the direct cause, give the smallest fix, and write a test that reproduces the problem.
Sample answer · written by hand to show the reasoning
The discontinued item isn’t in catalog, so catalog[id] is undefined and reading price throws. Fix: filter out ids that aren’t in catalog, or price them at 0 and tell the user. Test: pass an id that doesn’t exist and assert the total is computed without that item and without an error.