Advanced debugging assistant that analyzes errors, suggests fixes, traces root causes, and sets up debugging environments.
Analyzes errors, traces root causes, suggests fixes, and sets up debugging environments.
/plugin marketplace add rafaelkamimura/claude-tools/plugin install rafaelkamimura-claude-tools@rafaelkamimura/claude-toolsAdvanced debugging assistant that analyzes errors, suggests fixes, traces root causes, and sets up debugging environments.
STOP → "How would you like to provide the error?"
1. Paste error message/stack trace
2. Point to log file
3. Describe the issue
4. Run failing command
5. Analyze recent crashes
Choose method (1-5):
Context Gathering
Parse Error Information
// Extract key information
const errorInfo = {
type: "TypeError",
message: "Cannot read property 'x' of undefined",
file: "src/components/UserList.jsx",
line: 45,
column: 12,
stack: [...],
timestamp: "2024-01-15T10:30:00Z"
};
Categorize Error Type
error_categories:
- Runtime Errors:
- TypeError
- ReferenceError
- RangeError
- Async Errors:
- Promise rejection
- Callback errors
- Race conditions
- Network Errors:
- Connection refused
- Timeout
- CORS issues
- Build Errors:
- Compilation failure
- Module not found
- Syntax errors
Deploy Analysis Agents
Trace Error Source
# Git blame to find when introduced
git blame -L 40,50 src/components/UserList.jsx
# Check recent changes
git log -p --since="2 days ago" src/components/UserList.jsx
Analyze Code Context
// Problem code
function UserList({ users }) {
return users.map(user => (
<div>{user.profile.name}</div> // Error here
));
}
// Analysis:
// - user.profile might be undefined
// - users might be null
// - Missing null checks
Check Dependencies
# Did dependencies change?
git diff HEAD~1 package-lock.json
# Check for breaking changes
npm outdated
Generate Fix Options
// Option 1: Add null checks
function UserList({ users = [] }) {
return users.map(user => (
<div>{user?.profile?.name || 'Unknown'}</div>
));
}
// Option 2: Add validation
function UserList({ users }) {
if (!users || !Array.isArray(users)) {
return <div>No users</div>;
}
return users.map(user => (
<div>{user.profile?.name}</div>
));
}
// Option 3: Add default props
UserList.defaultProps = {
users: []
};
Test Fixes
// Generate test cases
describe('UserList fix validation', () => {
test('handles null users', () => {
expect(() => UserList({ users: null })).not.toThrow();
});
test('handles users without profile', () => {
const users = [{ id: 1 }];
expect(() => UserList({ users })).not.toThrow();
});
});
Configure Debugger
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Debug Error",
"program": "${workspaceFolder}/src/index.js",
"stopOnEntry": false,
"breakpoints": ["src/components/UserList.jsx:45"]
}]
}
Add Debug Logging
// Temporary debug code
console.log('DEBUG: users =', JSON.stringify(users, null, 2));
console.log('DEBUG: user =', user);
console.log('DEBUG: user.profile =', user?.profile);
Set Up Remote Debugging
# Node.js
node --inspect-brk=0.0.0.0:9229 app.js
# Chrome DevTools
chrome://inspect
# VS Code attach
Generate Minimal Reproduction
## Steps to Reproduce
1. Start the application: `npm start`
2. Navigate to /users
3. Click "Load More"
4. Error appears in console
## Expected Behavior
Users list should load additional items
## Actual Behavior
TypeError: Cannot read property 'x' of undefined
## Environment
- Node: 18.17.0
- Browser: Chrome 120
- OS: macOS 14.0
Create Reproduction Script
// reproduce-error.js
const UserList = require('./src/components/UserList');
// This triggers the error
const problematicData = [
{ id: 1, name: 'User 1' }, // Missing profile
{ id: 2, profile: { name: 'User 2' } }
];
UserList({ users: problematicData });
// Cannot read property of undefined
obj?.property?.nested
// Array is not iterable
[...(array || [])]
// Async errors
try {
await someAsyncFunction();
} catch (error) {
console.error('Async error:', error);
}
# KeyError
value = dict.get('key', default_value)
# AttributeError
if hasattr(obj, 'attribute'):
obj.attribute
# IndexError
if len(array) > index:
array[index]
-- Connection timeout
SET statement_timeout = '30s';
-- Deadlock
BEGIN;
LOCK TABLE users IN SHARE ROW EXCLUSIVE MODE;
-- Missing index
CREATE INDEX idx_users_email ON users(email);
Profile Performance
console.time('operation');
// Slow operation
console.timeEnd('operation');
// Memory profiling
console.log(process.memoryUsage());
Identify Bottlenecks
# Node.js profiling
node --prof app.js
node --prof-process isolate-*.log
# Browser profiling
performance.mark('start');
// Code
performance.mark('end');
performance.measure('operation', 'start', 'end');
Test the Fix
# Run specific test
npm test -- UserList.test.js
# Run regression tests
npm test
Verify in Multiple Environments
# Different Node versions
nvm use 16 && npm test
nvm use 18 && npm test
# Different browsers
npm run test:chrome
npm run test:firefox
# Debug Report
## Issue Summary
**Error**: TypeError: Cannot read property 'name' of undefined
**Location**: src/components/UserList.jsx:45
**Severity**: High
**Status**: RESOLVED
## Root Cause
Missing null check for user.profile object when users array contains items without profile data.
## Solution Applied
Added optional chaining and default values:
```javascript
<div>{user?.profile?.name || 'Unknown'}</div>
## Error Pattern Database
### Common Patterns
```yaml
patterns:
- pattern: "Cannot read property .* of undefined"
solution: "Add null checks or optional chaining"
- pattern: "Module not found"
solution: "Check import paths and install dependencies"
- pattern: "ECONNREFUSED"
solution: "Check if service is running and port is correct"
- pattern: "CORS policy"
solution: "Configure CORS headers on server"
- pattern: "Maximum call stack"
solution: "Check for infinite recursion or circular dependencies"
/test-suite/review-code/tech-debt{
"autoFix": {
"enabled": true,
"types": ["null-check", "import", "syntax"]
},
"logging": {
"level": "debug",
"output": "debug.log"
},
"breakpoints": {
"onError": true,
"onWarning": false
}
}
Systematic Approach
Documentation
Prevention