Logic Bugs
When the app runs without errors but produces wrong results.
What Is a Logic Bug?
A logic bug is when your app does not crash or show any errors, but it produces wrong results. Examples:
- A total that adds up incorrectly
- A list sorted in the wrong order
- A date showing one day earlier than expected
- A filter showing items it should not
- A counter that skips numbers
Logic bugs are tricky because there are no error messages to copy. The app looks like it is working — it is just doing the wrong thing.
How to Identify Logic Bugs
The key is to compare expected vs. actual with specific values:
| Bad Description | Good Description |
|---|---|
| "The total is wrong" | "I added 3 items at $10 each. Expected: $30. Actual: $20." |
| "The sort is broken" | "Items should be newest first but 'March 1' appears before 'March 5'." |
| "Dates are wrong" | "I entered March 5 but the app shows March 4." |
The more specific you are, the faster Claude can find the bug.
Describing Logic Bugs to Claude
Report a logic bug with expected vs. actual
Claude promptmy-app-name: I found a logic bug.
Expected: When I add 3 items at $10 each, the total should show $30.
Actual: The total shows $20.
The calculation seems wrong. Can you find where the total is computed and fix it?
Ask Claude to trace the data flow
Claude promptmy-app-name: The list page shows items in the wrong order. They should be sorted by date (newest first) but they appear in random order.
Can you find where the data is fetched and sorted, and fix the sort order?
When dates are wrong
Claude promptmy-app-name: Dates are displaying one day earlier than expected. For example, I enter March 5 but it shows March 4.
This might be a timezone issue. Can you investigate and fix the date handling?
Common Causes
- Off-by-one errors: Counting starts at 0 instead of 1, or a loop runs one too many/few times
- Timezone issues: Dates shift by a day because of UTC vs. local time conversion
- Wrong sort direction: Ascending when it should be descending, or vice versa
- Incorrect filter logic: Using "AND" when it should be "OR", or the wrong comparison operator
- Missing null checks: Calculations that break when a value is missing or undefined
Preventing Logic Bugs
Ask Claude to add verification:
Ask Claude to verify calculations
Claude promptmy-app-name: Can you review the calculation logic on the [page name] page? I want to make sure totals, averages, and counts are computed correctly. Add some test cases or console.log statements to verify.
Quiz
Quiz
What is the BEST way to describe a logic bug to Claude?