Systematic approach to finding and fixing issues
# Get latest code
gco main
gpl
# Check issue details
gh issue view 456
gh issue comments 456
# Try to reproduce
npm run dev
# Follow steps from issue
# Check logs
tail -f logs/app.log
npm run logs
# System state
btop # CPU/Memory usage
duf # Disk space
ps aux | grep node
# Network
netstat -an | grep LISTEN
lsof -i :3000
# Git bisect to find breaking commit
git bisect start
git bisect bad HEAD
git bisect good abc123 # Last known good
# Test each commit
npm test
git bisect good # or bad
# When found
git bisect reset
git show <bad-commit>
" DAP (Debug Adapter Protocol) is managed by lazy.nvim
:Lazy install nvim-dap
:Lazy install nvim-dap-ui
" Set breakpoint
<leader>db " Toggle breakpoint
<leader>dB " Conditional breakpoint
" Start debugging
<leader>dc " Continue
<leader>di " Step into
<leader>do " Step over
<leader>dr " Open REPL
" Using pdb
:!python -m pdb %
" Or insert breakpoint in code
import pdb; pdb.set_trace()
" Neovim DAP
<leader>dc " Start/Continue
<leader>dn " Step over
<leader>ds " Step into
# Start with inspector
node --inspect app.js
node --inspect-brk app.js # Break on first line
# With npm script
npm run debug
# Chrome DevTools
# Open chrome://inspect
# Basic debugging
python -m pdb script.py
# IPython debugger
pip install ipdb
python -m ipdb script.py
# In code
import ipdb; ipdb.set_trace()
# Monitor HTTP traffic
# Install mitmproxy
mitmproxy -p 8888
# Or use browser tools
open -a "Chrome" --args --proxy-server="localhost:8888"
# API testing
http --verbose GET api.example.com/users
curl -v https://api.example.com/users
# DNS issues
dig example.com
nslookup example.com
// JavaScript
console.log('User:', { id: user.id, name: user.name });
console.trace('Stack trace here');
console.time('operation');
// ... code ...
console.timeEnd('operation');
# Python
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.debug(f"User: {user.id}")
logger.error("Failed to connect", exc_info=True)
# Find errors
rg ERROR logs/
rg -i "exception|error|fail" logs/
# Time-based search
rg "2024-01-15 14:" logs/app.log
# Context around errors
rg -B5 -A5 "ERROR" logs/app.log
# Follow logs with filtering
tail -f logs/app.log | grep -i error
# Node.js profiling
node --prof app.js
node --prof-process isolate-*.log > profile.txt
# Chrome DevTools
node --inspect app.js
# Open Performance tab
# cProfile
python -m cProfile -o profile.out script.py
python -m pstats profile.out
# Line profiler
pip install line_profiler
kernprof -l -v script.py
# Node.js heap snapshots
node --inspect app.js
# Chrome DevTools > Memory > Take Snapshot
# Python memory profiling
pip install memory-profiler
python -m memory_profiler script.py
# System level
htop
ps aux --sort=-%mem | head
-- PostgreSQL
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
-- Show slow queries
SELECT query, calls, mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;
# Monitor queries in real-time
# PostgreSQL
tail -f /var/log/postgresql/postgresql.log
# MySQL
tail -f /var/log/mysql/mysql.log
# Via application
DEBUG=knex:query npm run dev
# Test database connection
psql -h localhost -U username -d database
# Check connections
SELECT * FROM pg_stat_activity;
# Network connectivity
telnet localhost 5432
nc -zv localhost 5432
// Breakpoints in code
debugger;
// Conditional breakpoints
if (user.role === 'admin') debugger;
// Console methods
console.log('%c Important! ', 'color: red; font-size: 20px');
console.table(users);
console.group('User Details');
console.log(user);
console.groupEnd();
# Install extension
# Chrome: React Developer Tools
# In console
$r # Selected component instance
$r.props
$r.state
# Find components
document.querySelector('[data-testid="user-profile"]')
# Comment out half the code
# If bug persists, it's in uncommented half
# Repeat until found
# Or with git
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
## Problem Description
The user authentication fails when...
## What I've Tried
1. Checked the API endpoint - returns 200
2. Verified token is sent - yes, in headers
3. ...
## Current Understanding
The issue seems to be...
## Next Steps
- Check token expiration
- Verify CORS settings
- ...
# Create minimal test case
mkdir bug-reproduction
cd bug-reproduction
npm init -y
# Add only necessary code
cat > index.js << 'EOF'
// Minimal code that reproduces the issue
const problematicFunction = () => {
// ...
};
EOF
# Test
node index.js
# Compare environments
diff .env .env.example
# Check environment variables
env | grep API
printenv | sort
# Node version issues
node --version
nvm use 18
# Clear caches
rm -rf node_modules package-lock.json
npm cache clean --force
npm install
# Check for conflicts
npm ls
npm outdated
npm audit
# Python
pip freeze > requirements.txt
pip install -r requirements.txt --force-reinstall
# File permissions
ls -la problem-file
chmod 644 file
chmod 755 directory
# Process permissions
sudo lsof -i :80
ps aux | grep process-name
# Fix npm permissions
npm config set prefix ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
# Create fix commit
gaa
gcm "fix: resolve authentication issue
The problem was caused by expired JWT tokens not being
refreshed properly. Added token refresh logic in the
auth middleware.
Fixes #456"
# Add test to prevent regression
v tests/test_auth_token_refresh.py
// Add assertions
console.assert(user.id, 'User must have ID');
// Add validation
if (!isValidEmail(email)) {
throw new Error(`Invalid email: ${email}`);
}
// Add monitoring
logger.info('Auth attempt', { email, ip: req.ip });
## Immediate Checks
- [ ] Can reproduce the issue?
- [ ] Check error messages/logs
- [ ] Recent changes (git log)
- [ ] Environment variables correct?
## Investigation
- [ ] Add debug logging
- [ ] Use debugger/breakpoints
- [ ] Check network requests
- [ ] Verify data flow
## Resolution
- [ ] Identify root cause
- [ ] Implement fix
- [ ] Add test for regression
- [ ] Document solution
# Quick commands
npm run debug # Start with debugger
<leader>db # Toggle breakpoint (Neovim)
console.trace() # Stack trace
debugger; # JS breakpoint
import ipdb; ipdb.set_trace() # Python breakpoint
rg ERROR logs/ # Search errors
git bisect # Find breaking commit
EXPLAIN ANALYZE # SQL query analysis