Prompt: Systematic Bug Investigation

A prompt that investigates bugs methodically, like a detective.

T

Tech Integration Labs

Author

Jan 22, 2026
3 min read

Prompt: Systematic Bug Investigation

Use when: Something's broken and you're not sure why. Works for UI bugs, API errors, data issues, and more.


The Prompt

I need help investigating a bug. Let me describe it:

**The Bug:**
1. What's happening? (symptom)
2. What should happen instead? (expected behavior)
3. When does it occur? (always / sometimes / specific conditions)
4. Any error messages? (paste them if yes)
5. Recent changes? (did anything change before the bug appeared?)

I'll investigate by:
- Tracing the code path from symptom to source
- Checking for recent changes that might have caused it
- Looking for similar patterns that might have the same issue
- Identifying the root cause (not just the symptom)
- Proposing a fix with explanation
- Suggesting tests to prevent regression

Describe the bug above and I'll investigate.

Example Output

Input:

  1. Users are seeing a blank screen after login
  2. Should redirect to dashboard
  3. Sometimes - seems random
  4. Console shows: "Cannot read property 'role' of undefined"
  5. Added new user roles feature yesterday

Claude's Investigation:

## Bug Investigation: Blank Screen After Login

### Root Cause Found
The new roles feature assumes `user.role` always exists, but users created before the migration don't have a role assigned.

**Location:** `src/auth/redirect.ts:23`
\\`\\`\\`typescript
// Current code - crashes when role is undefined
const dashboardUrl = ROLE_DASHBOARDS[user.role];

// user.role is undefined for pre-migration users
\\`\\`\\`

### Why It's Intermittent
- New users (post-migration): Have role assigned → works
- Old users (pre-migration): No role → crashes

### The Fix
\\`\\`\\`typescript
// Add default role fallback
const dashboardUrl = ROLE_DASHBOARDS[user.role ?? 'user'];
\\`\\`\\`

### Also Needed
1. Migration to backfill roles for existing users
2. Database constraint to require role on new users

### Regression Test
\\`\\`\\`typescript
test('handles user without role', () => {
  const userWithoutRole = { id: 1, email: 'test@test.com' };
  expect(() => getRedirectUrl(userWithoutRole)).not.toThrow();
});
\\`\\`\\`

Shall I implement these fixes?

Customization Options

With Browser Testing

After fixing, use the Chrome extension to verify the bug is resolved on the live site.

Production Investigation

Also check the production logs (provide log access) and look for related errors.
T

Tech Integration Labs

Building AI-powered systems and sharing what I learn along the way. Founder at Tech Integration Labs.

View Profile
Share this article:

Related Articles

View all →