Techniques for forcing error conditions in code to test error handling paths, including mock failure injection. Use when testing error handling, maze generation failures, or when error conditions are hard to trigger naturally. Create test scenarios to force error conditions and verify error handling works correctly.
Techniques for forcing error conditions in code to test error handling paths, including mock failure injection. Use when testing error handling, maze generation failures, or when error conditions are hard to trigger naturally. Create test scenarios to force error conditions and verify error handling works correctly.
Error Scenario Testing
Overview
Test error handling by forcing error conditions. Don't commit error handling code without testing error paths.
Forcing Error Conditions
Methods:
Add test mode flags to enable error injection
Create test seam commands to trigger errors
Temporarily modify code to force failures (revert after testing)
Use environment variables to enable error testing
See references/error-injection.md for detailed error injection patterns.
Maze Generation Error Testing
For maze generation failures:
Add forceMazeFailure() test seam command
Modify maze generation to fail after N attempts
Test fallback maze creation
Verify console warnings appear
See references/maze-generation-errors.md for specific patterns.
Error Testing Checklist
Error condition can be triggered
Error handling code executes
Fallback behavior works correctly
User experience is acceptable
Console warnings/logs appear
Game doesn't crash
Test Mode Pattern
See references/error-injection.md for test mode implementation pattern.
Test Seam Error Injection
Add test seam commands to trigger errors:
// Force error conditions via test seamwindow.__TEST__.commands.forceMazeFailure = () => {
// Force maze generation to failthis.mazeGenerator.forceFailure = true;
};
window.__TEST__.commands.restoreMazeGeneration = () => {
// Restore normal maze generationthis.mazeGenerator.forceFailure = false;
};
## Error Handling Verification- [ ] Error condition can be triggered
- [ ] Error handling code executes
- [ ] Fallback behavior works correctly
- [ ] User experience is acceptable
- [ ] Console warnings/logs appear
- [ ] Game doesn't crash
Test fallback mechanisms:
# Test fallback by forcing error
agent-browser eval"window.__TEST__.commands.forceMazeFailure()"
agent-browser eval"window.__TEST__.commands.generateMaze()"# Verify fallback maze is created
agent-browser eval"window.__TEST__.gameState().maze"
# Test recovery after error
agent-browser eval"window.__TEST__.commands.forceMazeFailure()"
agent-browser eval"window.__TEST__.commands.generateMaze()"
agent-browser eval"window.__TEST__.commands.restoreMazeGeneration()"
agent-browser eval"window.__TEST__.commands.generateMaze()"# Verify normal generation works after recovery
Resources
references/error-injection.md - Test mode flags, test seam commands, environment variables
references/maze-generation-errors.md - Specific patterns for maze generation failures