Exercise: Bug Hunter¶
Level: Intermediate Time: 30-45 minutes Skills: Debugging, code exploration, testing
Objective¶
Practice debugging a broken application with Claude Code. This exercise contains intentional bugs for you to find and fix.
Setup¶
-
Navigate to this exercise directory:
-
Install dependencies:
-
Start Claude Code:
The Application¶
This is a simple task manager API with the following features: - Add tasks - List tasks - Mark tasks complete - Delete tasks
Problem: Users report that the application has several bugs. Your job is to find and fix them.
Tasks¶
Task 1: Explore the Codebase¶
Ask Claude to give you an overview of the application.
Hint: "Explain what this application does and how it's structured"
Task 2: Run the Tests¶
The tests should reveal some of the bugs.
Hint: "Run the tests and show me which ones fail"
Task 3: Investigate Bug #1 - Tasks Not Saving¶
Users report that sometimes tasks disappear. Find why.
Hints: - Check how tasks are stored - Look at the add task function - Is data persisting correctly?
Task 4: Investigate Bug #2 - Wrong Completion Status¶
Marking a task complete doesn't always work.
Hints: - Check the complete task function - Look at how the status is updated - Compare the update logic with the data structure
Task 5: Investigate Bug #3 - Delete Fails Silently¶
Deleting a non-existent task should return an error, but doesn't.
Hints: - Check the delete function - What happens when the task ID doesn't exist? - Is there proper error handling?
Task 6: Fix All Bugs¶
Work with Claude to fix each bug. After each fix: 1. Run the specific test for that bug 2. Verify it passes
Task 7: Add a Missing Test¶
Notice there's no test for listing completed tasks only. Add one.
Files to Examine¶
02-bug-hunter/
├── src/
│ ├── index.js # Main application
│ ├── taskManager.js # Task management logic (bugs are here!)
│ └── storage.js # Data storage
├── tests/
│ └── tasks.test.js # Test file
├── package.json
└── README.md
Success Criteria¶
- [ ] All existing tests pass
- [ ] You can add a task and see it listed
- [ ] Marking a task complete works correctly
- [ ] Deleting a non-existent task returns an error
- [ ] New test for listing completed tasks passes
Bug Details (Spoilers!)¶
Bug #1 Hint
Check `taskManager.js` - is the task being saved after creation?Bug #2 Hint
Look at the `completeTask` function. Is it comparing IDs correctly?Bug #3 Hint
The `deleteTask` function doesn't check if the task exists before trying to delete.Reflection Questions¶
- How did Claude help identify the bugs?
- What debugging strategies did you use?
- How would you prevent similar bugs in the future?